I have a SQL query which includes the following SELECT terms:
SUM(CASE WHEN JobResponses.result = "true" THEN 1 ELSE 0 END) AS [True],
SUM(CASE WHEN JobResponses.result = "false" THEN 1 ELSE 0 END) AS [False],
However, when I use this is a SQL Server query, I got the syntax error:
Invalid column name 'true'.
obviously result
is the reference to the column name, so why am I getting this error? It seemed to work fine on SQLite??
You're using " around true and false, should be ' single quote.
SQL uses " as a Column identifier.
Using Single Quotes will solve the problem:
SUM(CASE WHEN JobResponses.result = 'true' THEN 1 ELSE 0 END) AS 'True',
SUM(CASE WHEN JobResponses.result = 'false' THEN 1 ELSE 0 END) AS 'False',
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.