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
 replace query

Author  Topic 

rajnidas
Yak Posting Veteran

97 Posts

Posted - 2014-10-09 : 03:06:53
hi all

i need help from your side i have post query below .

SELECT Id,Symptoms, replace (Symptoms,3,'Three')as symptons FROM temp table

out put is this
-----------------
Id Symptoms symptons
2003 2 2
2004 4|3|2| 4|Three|2|
3003 2 2
2005 4|3|2| 4|Three|2|
2007 3 Three


i need out put
-----------------
Id Symptoms symptons
2003 2 two
2004 4|3|2| four|Three|two|
3003 2 two
2005 4|3|2| four|Three|two|
2007 3 Three

Thanks & regards

Rajnidas


harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-10-09 : 04:26:06
Use CASE:

SELECT Id,Symptoms, 
case Symptoms
when 1 then 'One'
When 2 then 'Two'
When 3 then 'Three'
-- Write similar cases for other digits
else cast(Symptoms as varchar(10)) end as symptons
FROM temp table


Harsh Athalye
http://in.linkedin.com/in/harshathalye/
Go to Top of Page
   

- Advertisement -