TSQL多条记录集

时间:2017-05-17 09:00:39

标签: tsql

我正在使用游标循环遍历记录集并将值插入到另一个表中但是当我运行代码时的结果给出了3个不同的记录集,因为它在每次循环时将select打印到记录集中。我希望代码循环并插入但结果只显示包含@OUT_STATUS的最后一个记录集。

    DECLARE loop_Cursor CURSOR FOR  
((SELECT Picknote, noparts, nolines from dbo.pickdet where batchid =     @helpingwith )) 
OPEN loop_Cursor;  
FETCH NEXT FROM loop_Cursor;  
WHILE @@FETCH_STATUS = 0  
  BEGIN  
 INSERT into dbo.Pickdet (batchid,nolines,noparts,fullpart) VALUES     (@new_identity, @nolines, @noparts, 'Helper')
  FETCH NEXT FROM loop_Cursor;  
   END;  
CLOSE loop_Cursor;  
DEALLOCATE loop_Cursor;  

SELECT  @OUT_STATUS = 'SUCCESS',@OUT_STATUS_DESCRIPTION = 'Packing Batch Created' 


SELECT  @OUT_STATUS as out_status,@OUT_STATUS_DESCRIPTION as out_status_description,  @new_identity AS new_identity, @pickingnow AS old_id

0 个答案:

没有答案