| Author |
Topic |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-12-21 : 02:34:21
|
| i'm doing the following:select id,lastname+',' +firstname as cname usually this returns the lastname,firstname as I want but if the lastname or firstname it returns blank rather then the lastname/firstname (whichever is not blank.) Am i doing something wrong? |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2005-12-21 : 02:49:19
|
ahhh.... there are probably null values here, handle the null values with coalesce or issnullselect id,COALESCE(lastname, '') + ',' + COALESCE(firstname, '') as cnameDuane. "It's a thankless job, but I've got a lot of Karma to burn off." |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-12-21 : 02:58:56
|
| thnaks -- this is actually in access and not sql server - any idea for the correct syntax? |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2005-12-21 : 03:06:35
|
No, sorry - don't know the access syntax, but you should have put this in the Access Forum [url]http://www.sqlteam.com/forums/forum.asp?FORUM_ID=3[/url]Duane. "It's a thankless job, but I've got a lot of Karma to burn off." |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-21 : 03:08:47
|
| select id,IIF(Isnull(lastname)=1, '',lastname)) + ',' + IIF(Isnull(lastname)=1, '',firstname)) as cname from yourTableMadhivananFailing to plan is Planning to fail |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-12-21 : 03:21:53
|
| thanks for your help but it is still returning blanks..select id,IIF(Isnull(lastname)=1,'',lastname) + ',' + IIF(Isnull(lastname)=1, '',firstname) as cname |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-21 : 04:05:44
|
| Post some sample data and the result you wantMadhivananFailing to plan is Planning to fail |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-12-21 : 04:12:22
|
| samele data woudl be firstname lastnamejohn doe smithabejoe shmoeas you see some of the firstnames are missing and some of the lastnamesi wante it to returndoe,johnsmith,,abeshmoe,joebasically return what information i have |
 |
|
|
thiyait
Yak Posting Veteran
70 Posts |
Posted - 2005-12-21 : 04:36:55
|
quote: Originally posted by esthera samele data woudl be firstname lastnamejohn doe smithabejoe shmoeas you see some of the firstnames are missing and some of the lastnamesi wante it to returndoe,johnsmith,,abeshmoe,joebasically return what information i have
just try this maselect id,IIF(Isnull(lastname)=1,'',lastname) & ',' & IIF(Isnull(lastname)=1, '',firstname) as cname |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-12-21 : 04:48:05
|
| thanks that seems to work! |
 |
|
|
|