请教一个问题:MSSQL 游标,结果集有两个,我如果将两个结果集合并呢,代码如下
网上查了一点资料,大概都是都插入临时表,但是在那个地方插入呢?如果写代码呢?
DECLARE cur CURSOR
FOR select stockcd from bistk01t where status=1 and stockcd IN('B340','B310R')
OPEN cur
DECLARE @id varchar(10)
FETCH NEXT FROM cur INTO @id
WHILE(@@FETCH_STATUS = 0)
BEGIN
select a.itemcd, b.stockcd ,a.jqty '收付账数量', b.stockqty '库存数量', b.qcqty '待检数量(qc)'
, a.jqty - b.stockqty '差异' from ufn_mmmr033('','',@id,'','','20150122','20150122','0') a
left join insti01t b (nolock) on a.itemcd=b.itemcd and b.stockcd=@id
where kind=9
FETCH NEXT FROM cur INTO @id
END
CLOSE cur
DEALLOCATE cur
------解决思路----------------------
CREATE TABLE #temp(...)
DECLARE cur CURSOR
FOR select stockcd from bistk01t where status=1 and stockcd IN('B340','B310R')
OPEN cur
DECLARE @id varchar(10)
FETCH NEXT FROM cur INTO @id
WHILE(@@FETCH_STATUS = 0)
BEGIN
INSERT INTO #temp
select a.itemcd, b.stockcd ,a.jqty '收付账数量', b.stockqty '库存数量', b.qcqty '待检数量(qc)'
, a.jqty - b.stockqty '差异' from ufn_mmmr033('','',@id,'','','20150122','20150122','0') a
left join insti01t b (nolock) on a.itemcd=b.itemcd and b.stockcd=@id
where kind=9
FETCH NEXT FROM cur INTO @id
END
CLOSE cur
DEALLOCATE cur
SELECT * FROM #temp
DROP TABLE #temp