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 / deepak

declare @Str As varchar(100)
declare @StrNew As varchar(100)
-- You can set any string (max 100 len)
set @Str = 'Bhaskar'
set @StrNew = @Str
declare @PrintVal varchar(10)


While @StrNew <> ''
BEGIN
set @StrNew = Replace(@Str, left(@Str, 1), '')
set @PrintVal= (left(@Str,1) + cast((len(@Str)-Len
(@StrNew)) as varchar(5)))
print @PrintVal + ' ' + @StrNew +' ' +@Str
set @Str = @StrNew
END

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to select some specific rows from a table in ms sql server?

660


what is create database syntax? : Sql server database administration

708


How to generate create procedure script on an existing stored procedure?

594


How do I change my passwords (database, LDAP, and so on) without causing an outage?

680


What is the fastest way to permanently delete a 1 million row table named customers?

734






What is the order by used for?

710


How many clustered indexes there can be on table ?

682


What are the basic functions for master, msdb, model, tempdb databases?

672


What is difference between commit and rollback when used in transactions?

576


How to create “dependant” parameter “make, model, year”

95


What is a scheduled job or what is a scheduled task?

618


How to execute stored procedure and set temp table in sql server?

629


How to use order by with union operators in ms sql server?

662


What are the advantages of using a stored procedure?

633


What does it mean to normalize a database and why would you do it?

635