Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I would need to use the value from the field as is if it is something else than 0 or NULL. If it is 0 or NULL, replace it with 1. I thought something like this:CASE MyFieldWHEN 0 THEN 1 WHEN IS NULL THEN 1ELSE MyFieldENDBut it doesn't seem to work, gives me an error pointing to that is (i.e. I'm pretty sure I use the IS NULL in some wrong way).
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-04-17 : 09:03:55
A slight change to the syntax:
CASE WHEN MyField = 0 THEN 1 WHEN MyField IS NULL THEN 1 ELSE MyFieldEND
You can play with that and do all other kinds of variations. For example, both of these should result in the same behavior:
CASE WHEN COALESCE(Myfield,0) = 0 THEN 1 ELSE MyFieldEND