作者:常山他爹没有JJ2000_836 | 来源:互联网 | 2023-09-15 18:38
Howisitpossibletousedeclaredparameter,aWITHclauseandacursorinoneQuery如何在一个Query中使用声
How is it possible to use declared parameter, a WITH clause and a cursor in one Query
如何在一个Query中使用声明的参数,WITH子句和游标
declare @TOP10 table (Cat Nvarchar(max),SubGUID uniqueidentifier)
declare @Sub uniqueidentifier
declare GUID_Cursor cursor FOR
(select SubGUID from dbo.Sub with(nolock) where year=2016)
;
with [MyTable] as
(
Select SubGUID, color from dbo.Cars with(nolock) where color ='blue'
)
open GUID_Cursor
fetch next from GUID_Cursor into @Sub
while @@FETCH_STATUS=0
begin
insert into @TOP10 (Cat,SubGUID)
select color,SubGUID from [MyTable]
where SubGUID=@Sub
fetch next from GUID_Cursor into @Sub
end
close GUID_Cursor
deallocate GUID_Cursor
select * from @TOP10
I just cant find a way tu open the cursor after using the WITH clause.
我在使用WITH子句后无法找到打开游标的方法。
Can anyone help me?
谁能帮我?
4 个解决方案