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)
 multiple replacements

Author  Topic 

chedderslam
Posting Yak Master

223 Posts

Posted - 2009-07-02 : 11:36:10
I have a column that might be one of several values, and each needs to be replaced with something different. So, how I do what I have below as a single statement?

SELECT Replace(sessionID, 'ABC', ' 1') As id
SELECT Replace(sessionID, 'DEF', ' 2') As id
SELECT Replace(sessionID, 'GHI', ' 3') As id

Thanks.

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-07-02 : 11:37:35
SELECT Replace(Replace(sessionID, 'ABC', ' 1'), 'DEF', ' 2')
and so on....
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-07-02 : 11:39:08
select sessionID = replace(replace(replace(sessionID,'ABC','1'),'DEF','2'),'GHI','3')

quote:
Originally posted by chedderslam

I have a column that might be one of several values, and each needs to be replaced with something different. So, how I do what I have below as a single statement?

SELECT Replace(sessionID, 'ABC', ' 1') As id
SELECT Replace(sessionID, 'DEF', ' 2') As id
SELECT Replace(sessionID, 'GHI', ' 3') As id

Thanks.

Go to Top of Page

chedderslam
Posting Yak Master

223 Posts

Posted - 2009-07-02 : 11:50:43
Perfect. Thanks guys.
Go to Top of Page
   

- Advertisement -