同事寫了一段SQL在SQL2000執行正常,但在SQL2008R2無法執行
SQL中是動態組一段declare cursor的語法
模擬了一下SQL大概如下
declare @sql nvarchar(4000),@c1 nvarchar(10),@c2 int
set @sql = N'declare cur cursor for select ''col1'' as col1 ,1 as col2'
exec sp_executesql @sql
open cur
fetch next from cur into @c1,@c2
while @@FETCH_STATUS = 0
begin
print @c1
fetch next from cur into @c1,@c2
end
close cur
deallocate cur
在SQL2000執行正常,會print出 'col1'
但在SQL2008R2上,回傳了以下的錯誤
Msg 16916, Level 16, State 1, Line 3
A cursor with the name 'cur' does not exist.
Msg 16916, Level 16, State 1, Line 5
A cursor with the name 'cur' does not exist.
Msg 16916, Level 16, State 1, Line 11
A cursor with the name 'cur' does not exist.
Msg 16916, Level 16, State 1, Line 12
A cursor with the name 'cur' does not exist.
後來發現,在SQL2008R2另外幾個DB也可正常執行,就只有某個DB不行
查看了該DB的屬性,最後在option 的設定下有關Cursor的設定,有參數值Default Cursor = LOCAL,改成了GLOBAL後,就可利用dynamical sql宣告CURSOR了
訂閱:
文章 (Atom)
publish error allowDefinition='MachineToApplication'
一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...
-
上網找了免費的白箱檢測工具,找到了 puma scan 因為支援OWASP TOP 10的檢測,所以這是一個符合客戶需求又能與Visual studio結合的工具(白話說...交差了事矣....) 更重要的是這不用錢....檢測工具都貴森森的,尤其是源碼檢測工具。 ht...
-
在一台windows 2016的主機上,某一天,用遠端登入後,出現了以下的訊息.... 遠端工作階段中斷,因為沒有提供授權的遠端桌面授權伺服器可以使用。請連伺服器系統管理員。 這啥啊........... 想不到,在MOBILE01找到了解決...........哈哈...
-
SQL Server 2005 後,提供EXCEP 和INTERSECT, 功能和ORACLE的MINUS, INTERSECT相同 EXCEP 找出存在於第一個子集,但不存在於第二個子集的筆數 INTERSECT 找出皆存在於二個子集中的筆數 這二個方法很方便查找有多...