如何在SQLServer 2008中对字符串进行Cancatinate [英] How to Cancatinate String in sqlserver 2008

查看:73
本文介绍了如何在SQLServer 2008中对字符串进行Cancatinate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

在Sqlserver中,我想对一个字符串进行结尾,字符串名称是AnilKumar,我想计算AnilKumar中有多少个A.在AnilKumar字符串中,结果应该是两个A.

输出:A''s = 2名称应变为nilkumr


请提出一些建议,


问候,

AnilKumar.D

Dear Friends,

Here in Sqlserver i want to ConCatinate One String,The String name is AnilKumar i want to Count How many A''s in AnilKumar.In AnilKumar String there are two A''s the Result should Come.

Output: A''s=2 name should become nilkumr


Please suggest some suggestions,


Regards,

AnilKumar.D

推荐答案

SELECT 'ls'+cast(LEN(Customername ) - LEN(REPLACE(Customername , 'l', '')) as varchar(50)) from Customer WHERE (Customername = 'SunilSunilAnil')

..请尝试


您使用+进行串联.但是,由于您希望拥有计数,因此可以使用类似
的方法
You concatenate using +. But since you want to have count, you could use something like
SELECT 'A''s' + CONVERT( varchar(100), (SELECT COUNT(*) 
                                       FROM TableName
                                       WHERE ColumnName = 'A'))
...


这篇关于如何在SQLServer 2008中对字符串进行Cancatinate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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