由于某种原因,ORDER BY Case语句出错

时间:2015-04-30 13:21:53

标签: sql ms-access asp-classic

我有这个ORDER BY SQL语句(在asp经典编程中),对于一些reasson我一直得到错误:

error '80004005'
/tools.asp, line 292

在逐个更新我的SQL后出现错误。第292行也是SQL的优秀语句。所以我的Order by Case声明显然出了问题,但我真的不知道是什么......

我的SQL:

strSQLtw = "SELECT * FROM tariefnummers WHERE TariefOpWeb=TRUE AND Tariefnummer IN ('CD','CS','CG','DR','CA','CF','FD','FM','FR','BF','BW') ORDER BY CASE WHEN Status = 'CD' THEN 1 WHEN Tariefnummer = 'CS' THEN 2 WHEN Tariefnummer = 'CG' THEN 3 ELSE 4 END"
   Set rstTw = Con.Execute(strSQLtw)

2 个答案:

答案 0 :(得分:1)

你能试试吗

strSQLtw = "SELECT * FROM tariefnummers WHERE TariefOpWeb=TRUE AND
            Tariefnummer IN ('CD','CS','CG','DR','CA','CF','FD','FM','FR','BF','BW') 
            ORDER BY CASE Tariefnummer WHEN 'CD' THEN '1' WHEN 'CS' THEN '2' WHEN 'CG' THEN '3' ELSE '4' END"

Set rstTw = Con.Execute(strSQLtw)

答案 1 :(得分:0)

想出来,我在使用Access数据库时使用的是SQL Server语言。 Access SQL不接受ORDER BY CASE。用Switch语句修改它。