用一条sql语句好象不行,用存储过程把
解决方案 »
- sql server 2005 和 sql server 2000比較有哪里方面的不同
- 存储过程参数的问题
- MSSQL 2000 分表 查询
- sql server 2008 局域网连接问题
- sql server 2005的 字段扩展属性如何使用?
- 请教:存储过程内能够实现递规调用吗?
- 我想在单机上模拟学习sqlserver2000,请问是否一定要在2000server下安装。2000professional可以吗?功能上有差别吗?
- 哪位帮我看看出了什么问题?
- 编辑框如何分行显示SQL Server数据库表中某一项的内容?请高手指点!
- SELECT语句,if(value==null) vaule = "" 的写法,急!!!!!
- 判断表和存储过程
- 关于临时表的小问题???
declare c_sale cursor for select a.id from a,b where a.id=b.id1 and a.filed2=b.filed2
open c_sale
fetch c_sale into @id
while @@fetch_status=0
begin
delete from a where id=@id
fetch next from c_sale into @id
end
close c_sale
deallocate c_sale
go
@Max1 int, @Min1 int, @Max2 int, @Min2 int
Create Table #33 (id(自动加一), Fields3 int)
Select @Max1=Max(表A中最大的自动加一的ID号) From A
Set @Min1 = 1
While @Min1<=@Max1
begin
Select @Fields1=Fields1, @Fields2=Fields2 From A Where 自动加一的ID号 = @Min1
Insert #33 (Fields2) Select Fields2 From B Where Fields1 = @Fields1
Select @Max2=Max(id) From #33
Set @Min2 = 1
Wihle @Min2<=@Max2
begin
Select @Fields3=Fields3 From #33 Where ID = @Min2
if @Fields3=@Fields@ then
begin
Delete From A Where 自动加一的ID号 = @Min1
end;
Set @Min2 = @Min2 +1
end;
Set @Min1 = @Min1 +1
end;
应该是 Insert #33 (Fields3) Select Fields2 From B Where Fields1 = @Fields1
我的电脑没装SQL而且好久没用了,比较生疏,
如果答的不好,不要见怪,
@Max1 int, @Min1 int, @Max2 int, @Min2 int
Create Table #33 (id(自动加一), Fields3 int)
Select @Max1=Max(表A中最大的自动加一的ID号) From A
Set @Min1 = 1
While @Min1<=@Max1
begin
Select @Fields1=Fields1, @Fields2=Fields2 From A Where 自动加一的ID号 = @Min1
Create Table #33 (id(自动加一), Fields3 int)
Insert #33 (Fields2) Select Fields2 From B Where Fields1 = @Fields1
Select @Max2=Max(id) From #33
Set @Min2 = 1
Wihle @Min2<=@Max2
begin
Select @Fields3=Fields3 From #33 Where ID = @Min2
if @Fields3=@Fields@ then
begin
Delete From A Where 自动加一的ID号 = @Min1
end;
Set @Min2 = @Min2 +1
end;
Drop table #33
Set @Min1 = @Min1 +1
end;
create Table A
(
aa varchar(2),
bb int
)create Table B
(
aa varchar(2),
bb int
)insert into a
select 'aa',8
union
select 'bb',4insert into b
select 'aa',7
union
select 'bb',4
执行语句:
delete a from a,b
where a.aa = b.aa and a.bb = b.bbselect * from a
结果集:
aa 8