| Author |
Topic |
|
vijaynetpart
Starting Member
18 Posts |
Posted - 2009-06-08 : 05:56:21
|
| i have a 3 columns Address1, Address2, Address3..All are optional..I have concatenated the columns.... Address1+','+Address2+','+Address3I like to remove the , which are not have a value... |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-08 : 05:58:47
|
| try this..isnull(Address1,'')+isnull(Address2,'')+isnull(Address3,'')Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-06-08 : 06:18:06
|
| coalesce(Address1+',','')+ coalesce(Address2+case when address3 is not null then ',' else '' end,'')+ coalesce(address3,'')MadhivananFailing to plan is Planning to fail |
 |
|
|
vijaynetpart
Starting Member
18 Posts |
Posted - 2009-06-08 : 08:17:20
|
| Address1 Address2 Address3Add1 - Add3Add1 Add2 -- Add2 Add3I like to get below resultAdd1,Add3Add1,Add2Add2,Add3 |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-08 : 08:34:29
|
| Have u tried the above solution?? It will work for your case. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-08 : 09:05:57
|
| have u expect with ','Try this...isnull(Address1+',','')+isnull(Address2+',','')+isnull(Address3+',','')Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
 |
|
|
vijaynetpart
Starting Member
18 Posts |
Posted - 2009-06-08 : 09:22:05
|
| Senthil plz understamd my question.....I found the result..........Create Table #tmp(Address1 nVarchar(20),Address2 nVarchar(20),Address3 nVarchar(20))Insert Into #tmp(Address1,Address2,Address3)Select 'Add1','Add2','Add3'Union AllSelect 'Add1',Null,'Add3'Union AllSelect 'Add1','Add2',NullUnion AllSelect Null,'Add2','Add3'Union AllSelect Null,Null,'Add3'Union AllSelect Null,'Add2',NullUnion AllSelect 'Add1',Null,NullUnion AllSelect Null,Null,NullSelect * From #tmpSelect Replace(Replace(Replace(IsNull(Address1,',-')+','+IsNull(Address2,',-')+','+IsNull(Address3,'-,'),',-,',''),',-,',''),'-,','')From #tmp |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-08 : 09:42:37
|
| try thisselect isnull(reverse(stuff(reverse(isnull(Address1+',','')+isnull(Address2+',','')+isnull(Address3+',','')),1,1,'')),'')from #tmp |
 |
|
|
|
|
|