2017-06-01 145 views
-2

我收到此錯誤:SQL查詢錯誤2012

Incorrect syntax near the keyword 'set'.

這裏是代碼片段

'Update ' + @TableName +' set status='+str(@status)+ ' where id in (Select Sid from '[email protected]+' where SiteId=' + str(@SiteId) + ' and OtId = '+str(@OtId) + ' and (coalesce(VID,'''')='''' OR VID = ''' + @VID +'''))' 
+0

什麼是你試圖執行的實際結果查詢? – David

+0

你傳遞的@TableName的值是多少? –

+0

打印結果查詢並查看 – Backs

回答

0

你很可能得到使用STR()領先的空格函數沒有指定長度,這是導致錯誤。例如,select str(1)返回1,其中有9個填充空格。

也可能發生的是@status> 10.在這種情況下,它將被截斷爲****。例如,select str(12345678910)返回***

因此,請不要使用STR()。使用CAST()CONVERT()。當然,這可能不是你唯一的問題,但我懷疑它是基於你提供的。我會閱讀評論,因爲我同意你沒有提供足夠的信息來調試此代碼。密切關注@返回的評論和使用PRINT(@yourQuery)下一次

MSDN on STR()

The specified length should be greater than or equal to the part of the number before the decimal point plus the number's sign (if any). A short float_expression is right-justified in the specified length, and a long float_expression is truncated to the specified number of decimal places. For example, STR(12,10) yields the result of 12. This is right-justified in the result set. However, STR(1223,2) truncates the result set to **.