2012-12-26 78 views
-2

我有一個sql語句在sql server上成功運行,但在vb.net上粘貼時出現語法問題。不正確的語法靠近關鍵字'.','endfrom''group'關鍵字附近的語法不正確

sql = "select distinct y.supplierID, y.Name," & _ 
      "StatusDesc=CASE when y.status='N' then 'NEW' " & _ 
      "when y.status='B' then 'BLACKLISTED'" & _ 
      "when y.status='Q' then 'QUALIFIED'" & _ 
      "when y.status='R' then 'REJECTED' end , " & _ 
      "FlowStatusDesc = CASE when y.flowstatus='RC' then 'UNDER REVIEW'" & _ 
      "when y.flowstatus='PE' then 'POTENTIAL EXCLUSIVE'" & _ 
      "when y.flowstatus='PO' then 'POTENTIAL ORDINARY' ELSE '' end," & _ 
      "orderno=case when y.status='N' and y.flowstatus='' then '1'" & _ 
      "when y.status='N' and y.flowstatus<>'' then '2' " & _ 
      "when y.status='R' and y.flowstatus='' then '3'" & _ 
      "when y.status='R' and y.flowstatus<>'' then '4'" & _ 
      "when y.status='Q' and y.flowstatus='' then '5'" & _ 
      "when y.status='Q' and y.flowstatus<>'' then '6'" & _ 
      "when y.status='B' and y.flowstatus='' then '7' " & _ 
      "when y.status='B' and y.flowstatus<>'' then '8' else '9' end " & _ 
      "from (select x.supplierID, x.Name,x.Status,x.FlowStatus,x.AddWho" & _ 
      "from dbo.AP_Supplier x where x.AddWho IN (Select distinct b.UserID from dbo.SC_UserRole a left join dbo.SC_UserRole b ON a.RoleID=b.RoleID where [email protected])" & _ 
      "group by x.supplierID,x.Name,x.Status,x.FlowStatus,x.AddWho)y " & _ 
      "group by y.supplierID,y.name,y.status, y.flowstatus" & _ 
      "order by orderno" 
+0

您有正確的答案,請檢查您的所有空缺查詢。 – Steve

回答

2

在所有行的末端插入空格。例如。

"group by y.supplierID,y.name,y.status, y.flowstatus" & _ 
"order by orderno" 

結果字符串

group by y.supplierID,y.name,y.status, y.flowstatusorder by orderno 

這是一種語法錯誤英寸

+0

仍然出現同樣的錯誤。其他建議? –

+0

將生成的sql字符串打印到標籤上,並查看它與工作區域的不同之處。 – SWeko

+0

我已更正所有缺失的空格。只剩下一個不正確的語法並且靠近單詞'by'。我試過編輯,添加一切,但仍然沒有設法糾正不正確的語法錯誤 –

相關問題