1

I am trying to get my result as either 1 or 0 based on if the column note is empty or not

column is a varchar and i want the result from the query to give me a boolean value for that column note

SELECT id, product, note FROM myTABLE

what i tired is,

SELECT id, product, CASE WHEN ISNULL(note) THEN 0 ELSE 1 FROM myTable

but i am getting an error... i am sure there is simple fix to this i am missing so please help. thank you.

4

1 回答 1

2

Try

SELECT id, product,CASE WHEN note IS NULL THEN 0 ELSE 1 END as SomeColumn
FROM myTable

to check for blank and null as well, use NULLIF

SELECT id, product,
CASE WHEN NULLIF(note,'') IS NULL THEN 0 ELSE 1 END as SomeColumn
FROM myTable
于 2013-04-26T16:14:13.133 回答