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
How to select some specific rows from a table in ms sql server?
what is create database syntax? : Sql server database administration
How to generate create procedure script on an existing stored procedure?
How do I change my passwords (database, LDAP, and so on) without causing an outage?
What is the fastest way to permanently delete a 1 million row table named customers?
What is the order by used for?
How many clustered indexes there can be on table ?
What are the basic functions for master, msdb, model, tempdb databases?
What is difference between commit and rollback when used in transactions?
How to create “dependant” parameter “make, model, year”
What is a scheduled job or what is a scheduled task?
How to execute stored procedure and set temp table in sql server?
How to use order by with union operators in ms sql server?
What are the advantages of using a stored procedure?
What does it mean to normalize a database and why would you do it?