如何确定错误的位置

时间:2013-01-24 13:28:37

标签: sql-server

我有以下where语句,我一直收到与a)有关的错误,当我运行它时会弹出错误的语法错误。我无法弄清楚我犯了多少次错误。

WHERE     (dbo.COL_V_Cost.RRDD NOT LIKE '12%') AND (dbo.COL_V_COST.RRDD NOT LIKE '13%') AND (dbo.COL_V_Cost.RRDD NOT LIKE '2706%') AND (dbo.COL_V_Cost.RRDD NOT LIKE '2707%') AND (dbo.COL_V_Cost.RRDD NOT LIKE '2331%') AND (dbo.COL_TBL_VCOURSE.DEP_TYP_CD = 'H&S') AND (COL_V_COST.TNG_SYS_NR NOT ('0113','0197','0290','0489','0542','0974','1318','1322','1397','1401','1444','1446','1580'))

2 个答案:

答案 0 :(得分:1)

您错过了最后一个过滤器的IN

WHERE (dbo.COL_V_Cost.RRDD NOT LIKE '12%') 
  AND (dbo.COL_V_COST.RRDD NOT LIKE '13%') 
  AND (dbo.COL_V_Cost.RRDD NOT LIKE '2706%') 
  AND (dbo.COL_V_Cost.RRDD NOT LIKE '2707%') 
  AND (dbo.COL_V_Cost.RRDD NOT LIKE '2331%') 
  AND (dbo.COL_TBL_VCOURSE.DEP_TYP_CD = 'H&S') 
  AND (COL_V_COST.TNG_SYS_NR NOT IN ('0113','0197','0290','0489','0542','0974','1318','1322','1397','1401','1444','1446','1580'))
                                  ^-- this is missing

正确的语法是NOT IN

答案 1 :(得分:0)

你的最后一个AND应该是“NOT IN”