Sql Query替换语句 [英] Sql Query replace statement

查看:124
本文介绍了Sql Query替换语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有下表结构



表1

------ -

col1 col2

/Channel/channel1/img1.jpg 10

/Channel/channel2/img2.jpg 13

/Channel/channel1/img3.jpg 10





我需要更换/ Channel / channel1 / with/ Quote / 所以要替换我必须为所有频道编写不同的不同查询。

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.

UPDATE Table1
SET col1 = REPLACE(col1, '/Channel/channel1/', '/Quote/')
where col2 = 10


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



如何在单个查询或商店程序中替换请帮助



谢谢

Raj


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

Thanks
Raj

推荐答案

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


这篇关于Sql Query替换语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆