游標中使用變量表(請高手相助,謝謝!)
在存儲過程中定義一個游標,游標中的:cursor for select * from 表
中的表是一個變量;
declare @nowtbmonth varchar(20)
declare mycursor CURSOR FOR
execute('select distinct aaa as tablelist from '+@nowtbmonth+' order by tablelist')
上面是出錯的代碼:
Error: 在??字 'exec' 附近有?法??。 (State:37000, Native Code: 9C)