Recently, I came across an interesting problem with changing CASE statements to ISNULL functions in TSQL. The query I was working with is used to get some user attributes and permissions for the website I'm working on. The query used to have several CASE statements similar to the following:
NOTE: a.column1 in the example is of type bit in the table. Also note that the [CanDoSomething] result column is sometimes used as a row in a website.
SELECT ... CASE WHEN a.column1 IS NULL THEN 0 ELSE a.column1 END [CanDoSomething] ... FROM a
The DBA replaced these CASE statements with the ISNULL function:
SELECT ... ISNULL(a.column1, 0) [CanDoSomething] ... FROM a
This seems like a great change, but it caused something unexpected when retrieving data in C #. With the previous query, the value of the [CanDoSomething] column when accessing from a DataTable in C # was 1 or 0 . When we changed to using ISNULL , the value in C # was then changed to true or false , which, when processed as a string, do not explicitly match 1 or 0 .
Errors caused by this have already been fixed. I'm just wondering why ISNULL returns a different value than the equivalent CASE expression, and I cannot find answers on Google.
c # sql tsql
jvdub
source share