用“和"替换最后出现的逗号 [英] Replace last occurrence of comma with 'and'
本文介绍了用“和"替换最后出现的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的SQL查询返回的值类似于''a,b,c''.
我想用``and''替换最后一个逗号,最后看起来应该像是``a,b和c''.请帮忙.
My SQL query is returning a value like ''a,b,c''.
I want to replace last comma with ''and'', finally it should looks like ''a,b and c'' . Please help.
推荐答案
请参阅此
declare @str
set @str='a'
select case when charindex(',',reverse(@str))>0
then
reverse(replace(STUFF(reverse(@str),charindex(',',reverse(@str)),0,'#'),'#,',' dna '))
else
@str
end
祝您编码愉快!
:)
Happy Coding!
:)
这篇关于用“和"替换最后出现的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文