sql游标001

--游标

 

-- 申明游标 
declare cursor_001 cursor for select DICT_CODE,DICT_DESCRIBE,DICT_VALUE from @variable_Table
-- 开启游标
open cursor_001
fetch next from cursor_001 into @DICT_CODE,@DICT_DESCRIBE,@DICT_VALUE
while (@@fetch_status = 0)
begin
if exists(select top 1 OBJECT_ID from E3_MEASURE_U2000V1R7C00 where OBJECT_ID = @TDTNAME and DICT_CODE = @DICT_CODE and TDT = @STAND_TDT)
begin
update E3_MEASURE_U2000V1R7C00 set VALUE = @DICT_VALUE where OBJECT_ID = @TDTNAME and DICT_CODE = @DICT_CODE and TDT = @STAND_TDT
end
else
begin
insert into E3_MEASURE_U2000V1R7C00 values (@TDTNAME,''TDT'',@DICT_CODE,@DICT_DESCRIBE,@DICT_VALUE,@STAND_TDT)
end
fetch next from cursor_001 into @DICT_CODE,@DICT_DESCRIBE,@DICT_VALUE
end
close cursor_001
deallocate cursor_001 
set @count=@count-1
end
'
print @RunSQL
EXECUTE SP_EXECUTESQL @RunSQL

 

你可能感兴趣的:(sql,游标)