同事寫了一段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)
IIS 網站無法下載中文檔名檔案因為取消高位元字元
網址+中文檔案名稱方式下載檔案顯示 404 - 找不到檔案或目錄。 但英數字檔案名稱則可下載。 因為設定GCB IIS,其中1項 將高位元字元預設取消勾選了。 27 TWGCB-04-014-0028 要求篩選與其他限制模組 允許高位元字元 這項原則設定決定查詢...
-
一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...
-
Row.Cells[2].Text == "abc" ? "ok" : "not ok" ; 或加入Microsoft. VisualBasic 參考使用 vb namespace using Microsoft...
-
freeFTPd是套免費的SFTP SERVER支援22 port SFTP及21port FTP,一般找到免費的都不支援SFTP只有技援FTPS。 之前一直有個困擾在幾台主機安裝後,有幾台重開機後,SFTP SERVER必須手動去啟動,一直以來老是搞不懂為什麼,今天看到一篇文...
沒有留言:
張貼留言