Home > Uncategorized > SQL: WHEN CASE NULL fails. (via All Wrong)

SQL: WHEN CASE NULL fails. (via All Wrong)

Imagine you want to find all the null values in a column in a database table (SQL Server). x 1 2 NULL 4 5 Here is the SQL that performs the task as required: SELECT x, CASE x WHEN NULL THEN 'yes' ELSE 'no' END AS result FROM someTable The result he expected was: x result 1 no 2 no NULL yes 4 no 5 no But that isn't what he got. His result was like this: x result 1 no 2 no NULL no 4 no 5 no Curiously, if you run this: SELECT x, CASE x WHEN 1 THEN ' … Read More

via All Wrong

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: