我想在sql中替换字符串 [英] i want to replace string in sql

查看:97
本文介绍了我想在sql中替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面的问题

i想用其他字符串替换字符串ex:C:docs \ test\uml这是我的字符串,我想用这样替换它 C:docs \ firstname-lastname \\\ n

表格如下



作者表

authorid名字姓氏书籍位置

1 xyz abc C:\ docs \ test \ mul

2 opq def C:\ downloadof\test \ uml



现在我想要的结果如下



authorid firstname lastname bookslocation

1 xyz abc C:\docs \ xyz-abc \\\ n

2 opq def C:\downloads \ opq-def \uml



这里我想用作者的名字和姓氏替换 test



请帮帮我...

解决方案

1。在SQL中,您可以通过简单地将它们连接在一起来连接字符串:

 选择 firstname + '   - ' + lastname 



2. SQL也有< a href =https://msdn.microsoft.com/en-us/library/ms186862.aspx> REPLACE [ ^ ]方法:

 选择替换(base_path,'  test',firstname + '   -  + lastname)



(base_path是你的c: \\\ docs \ test \uml path ...)


I have question like below
i want to replace string with other string ex: C:docs\test\uml this is my string and i want to replace this by like this C:docs\firstname-lastname \uml
table is as below

author table
authorid firstname lastname bookslocation
1 xyz abc C:\docs\test\uml
2 opq def C:\downloads\test\uml

now i want result as below

authorid firstname lastname bookslocation
1 xyz abc C:\docs\xyz-abc\uml
2 opq def C:\downloads\opq-def\uml

here i want to replace test with firstname and lastname of author

please help me on this...

解决方案

1. In SQL you can concatenate strings by simply add them together:

select firstname + '-' + lastname


2. SQL also has a REPLACE[^] method:

select replace(base_path, 'test', firstname + '-' + lastname)


(base_path is your c:\docs\test\uml path...)


这篇关于我想在sql中替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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