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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help with query concatenate string based on value

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2008-10-14 : 13:36:29
Hi,

I have a query as such


SELECT 'string' + rank + 'aboutTheRank' FROM tbl

I want to modify it so that , depending on the value of rank, we append an appropriate string after it. There are just 2 different possible values (1,2)

How can I do this ?

For example below is what I want to accompish, but not the right syntax obviously ..

Thanks for any tips!
mike123


IF rank =1

SELECT 'string' + rank + 'aboutTheRank1' FROM tbl

If rank =2


SELECT 'string' + rank + 'aboutTheRank2' FROM tbl

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-14 : 13:38:57
use this

SELECT 'string' + rank + case when rank=1 then 'aboutTheRank1' else 'aboutTheRank2' end   
FROM tbl

Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2008-10-14 : 13:50:47
perfect, thank you ! :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-14 : 13:52:43
quote:
Originally posted by mike123

perfect, thank you ! :)



welcome
Go to Top of Page
   

- Advertisement -