How can count the string ?
for ex: If i have string like 'bhaskar' then i need like
b:1
h:1
a:2
s:1
k:1
r:1

please give any idea on that


Answer Posted / suni soni

In SQL Server 2005 New query window for any database.

declare @CharVal varchar(100),@i int
declare @temp table (CharVal varchar(10))

set @a='Bhaskar'

set @i=1
while (@i<=len(@a))
begin

insert into @temp values (substring(@a,@i,1))

set @i=@i +1

end

select CharVal, count(*) from @temp group by CharVal

Is This Answer Correct ?    10 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is resource governor in sql server?

650


How do I delete a sql server database?

634


What is the purpose of update statistics and scope_identity() function?

707


Explain about system database?

678


What are the types of database schema? : sql server analysis services, ssas

683






Define cursor locking

638


Explain contrast amongst grouped and non-bunched records?

606


Explain activity monitors

706


What is replace and stuff function in sql server?

646


what are database files and filegroups? : Sql server database administration

580


What are trace files?

611


What is the difference between functions and stored procedures?

701


User wants only to display only pdf as export option in report manager. How to achieve this?

187


Define the one-to-one relationship while designing tables.

593


What is the default Port No on which SQL Server listens?

716