Suppose I have a table like:
Tab(MyDate datetime null, MyIs bit null, ...)
Then I have SQL Like
select Isnull(MyDate, 1), IsNull(MyIs, 999) from Tab;
If MyDate, MyIs value is null in DB, the result is:
MyDate MyIs
1900-01-02 00:00:00.000 1
Not the expected value like
MyDate MyIs
1 999
So it looks like the return value is based on data type of the column.
How to resolve this issue?
For my testing case as above, I Only got one row from the table.
The way you’re looking for, you don’t.
All the values in the same column must be the same data type. If your data had NOT NULL values in some rows (returning the column’s data-type) and NULL values in other rows (returning a different data type, as per your
CASEstatement), you would break this requirement.You could have two extra fields…
You could
CAST()everything toVARCHAR()and return strings instead ofDATETIME,BITorINT.But, more probably, I’d review the reason you want to do this in the first place and work out an alternative design.