I am using MSSQL and need to write a query to have:
RESULT
------
abc
For example, if I have this table:
CREATE TABLE A (a int)
..and attempt to use:
SELECT IF a > 20 THEN开发者_如何学编程 'abc'
ELSE 'def'
END
FROM A
But it does not work with SQL. How is it possible?
SELECT
CASE WHEN a > 20 THEN 'abc'
ELSE 'def'
END
FROM A
select case when A.a > 20 then 'abc' else 'def' end
from A
---- added a week later ----
Geez, sorry to not have formatted my SQL, it was just a quick response! :)
SELECT CASE
WHEN A.a > 20 THEN 'abc'
ELSE 'def'
END AS derived
FROM A
精彩评论