开发者

IF AND ELSE to turn decimal values into string

开发者 https://www.devze.com 2023-02-19 19:48 出处:网络
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)

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

精彩评论

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