Using IsNull with different data types in SQL SERVER

Salil Singh 60 Reputation points
2025-06-06T18:06:46.15+00:00

Hi Team,

I am working on on premises SQL Server. I have a requirement where I need to apply left outer join between 2 tables and use IsNull to show default data when columns are having null. Under ISNULL, if a column is null what shall i put for below data types -

  1. Varchar.
  2. Int.
  3. Decimal (6,0)
  4. Date
  5. DateTime

Please let me know if any other info required from me.

Thanks,

Salil

SQL Server | SQL Server Transact-SQL
{count} votes

4 answers

Sort by: Most helpful
  1. Erland Sommarskog 128.6K Reputation points MVP Volunteer Moderator
    2025-06-06T18:17:06.1633333+00:00

    For varchar, you would typically use the empty string:

    isnull(stringcol, '')
    

    For remaining data types, you would need to ask your business stakeholders what they want to see.

    For numeric values 0 may make sense, but it can also be grossly misleading.

    Many times, you want the value to be blank in the presentation layer, and the simplest way to achieve that is to return NULL and let the presentation layer do the job.

    If you have a very primitive presentation layer, like SSMS, one alternative is to convert everything to string so that you can use a blank string to represent the NULL value. But this makes the code bulky, and also inflexible, particularly for date/time values, where you will have a fixed formatting. Date/time values are best formatted in the presentation layer according to the user's regional settings, so that one user can see 2025-06-01, and another can see 01/06/2025.


  2. SUMIT RAY 0 Reputation points
    2025-06-09T17:55:33.42+00:00

    ISNULL(column, default)

    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Naveen Kumar M 175 Reputation points
    2025-09-15T11:58:07.3+00:00

    You are applying a LEFT OUTER JOIN and using ISNULL to handle missing values.

    For ISNULL(expression, replacement_value), the replacement must be of the same or implicitly convertible datatype as the column.

    Suggested defaults for your data types:

    • Varchar: ISNULL(ColumnName, '') (empty string, or you can provide something like 'N/A' if business requires it)
    • Int: ISNULL(ColumnName, 0) (numeric 0 is safe; you can also choose -1 or another sentinel value if 0 is meaningful)
    • Decimal(6,0): ISNULL(ColumnName, 0) (decimal accepts 0.0; same rule as int)
    • Date: ISNULL(ColumnName, '1900-01-01') (SQL Server’s minimum safe date, often used as a default marker)
    • DateTime: ISNULL(ColumnName, '1900-01-01 00:00:00') (same as above, but with time part)

    Consideration:

    • The replacement value must be a literal of the same type (or convertible).
    • For date/datetime, ensure the format is unambiguous (YYYY-MM-DD).
    • Sometimes COALESCE is better than ISNULL (it’s ANSI standard and allows multiple fallbacks).
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.