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
Define tool Manage Statistics in SQL Server 2000 query ?
Tell me about builtinadministrator?
Do you know exporting and importing utility?
What is sub query and its properties?
How to apply filtering criteria at group level with the having clause in ms sql server?
what is a live lock? : Sql server database administration
What is bulkcopy in sql?
What is save transaction and save point?
Why I have to use stored procedures?
How can we rewrite sub-queries into simple select statements or with joins?
Mention the uses of stored procedures.
What is the difference in accessing db between sql server vs sql azure?
What are the database objects? : SQL Server Architecture
What are the different types of backups avaialabe in sql server 2005?
What is the recovery model?