cursor你看看,没有测试过。declare @y_heth varchar(20),@y_chanpbh varchar(20)
declare myCursor cursor for SELECT A.y_heth, A.y_chanpbh
FROM smi_het A
WHERE (not EXISTS
(SELECT 1
FROM tr_dind B
WHERE A.y_heth = B.kehdd)) open myCursor
fetch next from myCursor into @y_heth,@y_chanpbh
while @@FETCH_STATUS = 0
begin
exec add_tr_dd @y_heth,@y_chanpbh
fetch next from myCursor into @y_heth,@y_chanpbh
end
close myCursor
deallocate myCursor
declare myCursor cursor for SELECT A.y_heth, A.y_chanpbh
FROM smi_het A
WHERE (not EXISTS
(SELECT 1
FROM tr_dind B
WHERE A.y_heth = B.kehdd)) open myCursor
fetch next from myCursor into @y_heth,@y_chanpbh
while @@FETCH_STATUS = 0
begin
exec add_tr_dd @y_heth,@y_chanpbh
fetch next from myCursor into @y_heth,@y_chanpbh
end
close myCursor
deallocate myCursor
declare tb cursor for
SELECT A.y_heth, A.y_chanpbh
FROM smi_het A
WHERE (not EXISTS
(SELECT 1
FROM tr_dind B
WHERE A.y_heth = B.kehdd))declare @a varchar(5),@b varchar(8)
open tb
fetch next from tb into @a,@b
while @@fetch_status=0
begin
exec add_tr_dd @a,@b
fetch next from tb into @a,@b
end
close tb
deallocate tb
一条SQL语句及返回值如下:
declare @a varchar(100),@b varchar(100)
open cursor_insert
fetch cursor_insert into @a,@b
while @@fetch_status=0
begin
exec add_tr_dd @a,@b
fetch cursor_insert into @a,@b
end
close cursor_insert
deallocate cursor_insert
declare @a varchar(100),@b varchar(100)SELECT IDENTITY(int, 1, 1) as id, A.y_heth, A.y_chanpbh
INTO #tmp
FROM smi_het A
WHERE (not EXISTS
(SELECT 1
FROM tr_dind B
WHERE A.y_heth = B.kehdd))
SET @cnt = @@ROWCOUNTSET @i = 1
WHILE @i <= @cnt
BEGIN
SELECT @a = y_heth, @b = y_chanpbh FROM #tmp WHERE id = @i
exec add_tr_dd @a, @b
ENDDROP TABLE #tmp