Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,
I have below table structure

Table1
-------
col1 col2
/Channel/channel1/img1.jpg 10
/Channel/channel2/img2.jpg 13
/Channel/channel1/img3.jpg 10


I need to replace /Channel/channel1/ with "/Quote/" so to replace i have to write different different query for all channels.
SQL
UPDATE Table1
SET col1 = REPLACE(col1, '/Channel/channel1/', '/Quote/')
where col2 = 10


UPDATE Table1
SET col1 = REPLACE(col1, '/Channel/channel2/', '/Quote/')
where col2 = 13

How can i replace in a single query or store procedure please help

Thanks
Raj
Posted
Updated 22-Oct-13 3:28am
v2

1 solution

SQL
UPDATE Table1
SET col1 = 
    CASE 
        WHEN col2 = 10 THEN REPLACE(col1, '/Channel/channel1/', '/Quote/')
        WHEN col2 = 13 THEN REPLACE(col1, '/Channel/channel2/', '/Quote/')
    ELSE col1 END
 
Share this answer
 
Comments
Herman<T>.Instance 22-Oct-13 9:29am    
My 5+
Raj tilak Bose 22-Oct-13 9:40am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900