SQL SERVER – Check Database Level (IsNullConcat) and Session Level Settings (CONCAT_NULL_YIELDS_NULL) using T-SQL

Earlier I wrote a blog post SQL SERVER – A Quick Note on CONCAT_NULL_YIELDS_NULL and in follow up to the blog post, I received few questions. Let me try to answer those questions in following blog post.

Q: How do we know if setting which returns NULL when concated to another NULL value is ON at database level?

A: You can run following script to identify the settings of the database level. In my script I have described AdventureWorks database and is checking if the settings which returns NULL when any other value is concated with NULL or not. If the query returns 1 that means when any value is concated with NULL it will return NULL. If the query returns 0 it means when any value is concated with NULL, it will still return original value and impact of NULL will be ignored.

-- Check Database Level settings
SELECT DATABASEPROPERTYEX('AdventureWorks2012', 'IsNullConcat');

Q: How do we know if setting which returns NULL when concated to another NULL value is ON at session level?

A: You can run following script to identify the settings of the session level. If the query returns 1 that means when any value is concated with NULL it will return NULL. If the query returns 0 it means when any value is concated with NULL, it will still return original value and impact of NULL will be ignored.

-- Check Session Level settings
SELECT SESSIONPROPERTY('CONCAT_NULL_YIELDS_NULL');

Additionally, you can read comment of  Manigandan as he has demonstrated that we can also get the impact of function ISNULL with using another function COALESCE.

Reference: Pinal Dave (http://blog.sqlauthority.com)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s