Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to check for null or empty string
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

57 Posts

Posted - 07/25/2013 :  15:36:05  Show Profile  Reply with Quote
I am trying to check for a null or empty value for a column (nvarchar 7,null). if null or empty to return a value (1).

So far I tried isnull and Len without any luck.

select isnull(col1,'1') from table1 -- Returns 0 rows.

select CASE WHEN Len(col1) < 0 THEN '1' -- Returns 0 rows



James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/25/2013 :  15:43:59  Show Profile  Reply with Quote
SELECT * FROM YourTable WHERE col1 IS NULL OR col1 = '';
This will return even if col1 has just a space (or just multiple spaces).
Go to Top of Page

Yak Posting Veteran

62 Posts

Posted - 07/25/2013 :  15:54:37  Show Profile  Reply with Quote
select isnull(col1,'1') from table1 is right, but use number only. Do not use '' unless it is a string field.

select isnull(col1,1) from table1

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 07/26/2013 :  02:04:47  Show Profile  Reply with Quote
I prefer COALESCE to IS NULL as its ansi based and also deosnt have issues like this

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000