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)
 blank value
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1416 Posts

Posted - 11/08/2013 :  07:52:30  Show Profile  Reply with Quote
Hi, How do I show a text such as 'current' if there is nothing returned?
The following sql is not quite right because it just returns a blank value and not the value of 'current' that I would like
i.e.
select
field1 =
case when field1='' then 'current'
else field1
end
from tblMain where Field2=3

James K
Flowing Fount of Yak Knowledge

3649 Posts

Posted - 11/08/2013 :  08:17:24  Show Profile  Reply with Quote
quote:
Originally posted by arkiboys

Hi, How do I show a text such as 'current' if there is nothing returned?
The following sql is not quite right because it just returns a blank value and not the value of 'current' that I would like
i.e.
select
field1 =
case when field1='' then 'current'
else field1
end
from tblMain where Field2=3

That seems to be correct. The thing that may be tripping you up is that it might not be blank, it might be null. You can test that easily by making the following change to your query
select 
field1 = 
case when COALESCE(field1,'')='' then 'current'
else field1
end
 from tblMain where Field2=3
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.05 seconds. Powered By: Snitz Forums 2000