The following piece of code is returning 1900-01-01 when the DOB field is null. I wanted (and expected) it to return an empty string ('') but it's not. How should I proceed to get my desired results?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
You can't get an empty string because you're returning the
DATE value type from
Per the docs,
Returns the same type as check_expression. If a literal NULL is provided as check_expression, returns the datatype of the replacement_value. If a literal NULL is provided as check_expression and no replacement_value is provided, returns an int.
If you're checking whether or not the value is
NULL, there is no need to convert it to a date, unless you wanted to return a date value (which you don't seem to).
SELECT ISNULL( DOB , '')
Which will return
if the value is
NULL date is
NULL (no value). An empty string, on the other hand, evaluates to
0, which in SQL Server is implicitly an integer representing the number of days since