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 Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
197 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.3K 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

Your answer

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