SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

emyk
Yak Posting Veteran

50 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

SQL SERVER 2008.

thanks

James K
Flowing Fount of Yak Knowledge

3326 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

ugh3012
Yak Posting Veteran

56 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

visakh16
Very Important crosS Applying yaK Herder

India
52249 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

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000