Click here to Skip to main content
15,886,056 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted

SQL
SELECT 'ls'+cast(LEN(Customername ) - LEN(REPLACE(Customername , 'l', '')) as varchar(50)) from Customer WHERE (Customername = 'SunilSunilAnil')
..Pls try this
 
Share this answer
 
v3
Comments
Anil Honey 206 25-May-12 2:09am    
Error is Coming like this

Conversion failed while Converting varchar value l's to datatype int
sivasankari ts 25-May-12 2:15am    
wait
sivasankari ts 25-May-12 2:18am    
updated the solution .Pls check again
Anil Honey 206 25-May-12 2:20am    
I have tried its showing same error
Anil Honey 206 25-May-12 2:21am    
Hey thanks its Came thank you very much
You concatenate using +. But since you want to have count, you could use something like
SQL
SELECT 'A''s' + CONVERT( varchar(100), (SELECT COUNT(*) 
                                       FROM TableName
                                       WHERE ColumnName = 'A'))
...
 
Share this answer
 
Comments
Anil Honey 206 25-May-12 1:53am    
SELECT 'l''s' + CONVERT(varchar(20),
(SELECT COUNT(*) AS Expr1
FROM Customer
WHERE (Customername = 'SunilSunilAnil'))) AS 'Names'

Output is Coming like this
Names
l's1
But the OutPut Should Come l's3 Becoz three l's are there

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