开发者

IF AND ELSE to turn decimal values into string

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜