同事寫了一段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)
pdf.js 無法顯示部份字
有個檔案在pdf viewer套件中無法顯示內容,但下載檔案後使用工具又可以正常顯示。 本來以為是套件版本太舊的原因,於是去下載pdf viewer套件 https://github.com/mozilla/pdf.js 更新後還是一樣。 覺得應是字型缺漏的問題,於是用PDF-X...
-
上網找了免費的白箱檢測工具,找到了 puma scan 因為支援OWASP TOP 10的檢測,所以這是一個符合客戶需求又能與Visual studio結合的工具(白話說...交差了事矣....) 更重要的是這不用錢....檢測工具都貴森森的,尤其是源碼檢測工具。 ht...
-
建了一個工作排程,定時執行batch檔。 batch中寫了一段xcopy,主要針對有異動較新檔案時才複製。 echo off for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find...
-
.net 執行SQL指令時,出現以下錯誤。 已經開啟一個與這個 Command 相關的 DataReader,必須先將它關閉。 在web.config connectionstring 加入 "MultipleActiveResultSets=True...