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
 select statement

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2010-04-21 : 14:24:40
i need to Populate agg_besn column by concatenating agg and besn column
condition is : when agg is blank then '_' should not come
else it should concatenate with '_'

case statement should no used
Tried so far:

Select agg,besn,IsNull ( agg,'') + '_' + besn as agg_besn
From Port
actual out should be:
agg besn agg_besn
1.2 Prch 1.2_prch
Root Root

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-04-21 : 14:54:40
One way..
Select agg
,besn
,case when agg = '' then besn else agg + '_' + besn end as agg_besn
From Port
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 23:22:00
Select agg,besn,COALESCE(NullIF( agg,'') + '_','') + COALESCE(besn,'') as agg_besn
From Port

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -