你这种使用游标肯定错了。因为@@fetch_status不一致。你给出两的表结构,和两个表的测试数据,还有你要的结果数据。
然后大家给你写。
然后大家给你写。
解决方案 »
- 求教:关于insert into select ...和select into 性能比较。
- 跪求,泣求,高手救命,一SQL语句的优化,特急,解决就结贴
- DTS全局变量问题.
- 问一个SQL的条件查询,不知道问题出在哪里了
- 简单问题,up者有分!在线等待!
- 调试一个存储过程(主要作用就是生成一个临时表并插入数据)提示保存*.rpt文件???
- SQL高难度问题——三表相互查询的bbs原理,急求你来解决!
- 錯誤提示:[Microsoft][ODBC SQL Server Driver]String data, right truncation是甚麼?
- 涉及PIVOTServer的一个SQL语句问题!
- 怎样返回一个字符串的长度,函数是什么呢?MS SQL SERVER
- 一个关于存储过程中用cursor从xml中取数的问题!
- sql做服务端,access做客户端碰到的几个问题3
update order
set sid=2040
where not exists(select 1 from orderdetail b where order.id=b.id and b.flag<>0)
declare @PID int --ProductID
declare @OID int --OrderID
declare @flag intdeclare @flagcount int
declare @flag_total intselect @flagcount=0declare orderdetail_cursor cursor for
select pid,flag from OrderDetail
where oid = @OIDopen orderdetail_cursorfetch next from orderdetail_cursor into @PID,@flag
while @@fetch_status = 0
begin
if @flag = 0
begin
select @flagcount=@flagcount+1
fetch next from orderdetail_cursor into @PID,@flag
end else
if @flag > 0
begin
select @flagcount=-1
break
end
endselect @flag_total=count(flag) from OrderDetail
if @flagcount=@flag_total
begin
update [order] set sid = 2040 where oid = @OID
end
else
begin
update [order] set sid = -1 where oid = @OID
endclose order_cursor
deallocate order_cursor