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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 want to display null in a field

Author  Topic 

gongxia649
So Suave

344 Posts

Posted - 2006-09-20 : 13:48:08
ad1 ad2
-----------------------------
younge joe
null null
youn null

want a result like that. anyone can help me to do it?


ad1+ad2
-----------------------
younge joe
null
youn

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-20 : 13:53:51
Want to read the hint link in my sg and post what it asks for?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

gongxia649
So Suave

344 Posts

Posted - 2006-09-20 : 13:57:12
i want to write a code to concatenate 2 fields. But when the fields are null. It should also display null
Go to Top of Page

Gopi Nath Muluka
Starting Member

22 Posts

Posted - 2006-09-20 : 13:58:33
try this

select nullif(isnull(ad1,'')+isnull(ad2,''),'') as full1 from t1

Thanks,
Gopi Nath Muluka
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-20 : 14:00:17
NULLIF?

And let's be ANSI

SELECT COALESCE(ad1,'null')+' '+COALESCE(ad2,'null')



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-09-20 : 14:43:07
quote:

declare @table table
(f1 varchar(20) null,
f2 varchar(20) null,
result varchar(20)null )

insert @table (f1,f2)
select null, null union all
select null, 'amber' union all
select 'yui', 'kanth' union all
select 'donnal', null


select * from @table

update @table
set result = f1 + f2

select * from @table



Thanks for the prep work :)

set result = coalesce(f1 + ' ' + f2, f1, f2)

Be One with the Optimizer
TG
Go to Top of Page

gongxia649
So Suave

344 Posts

Posted - 2006-09-20 : 14:45:12
Gopi Nath Muluka, thanks it works
TG, it works too
Go to Top of Page
   

- Advertisement -