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
What are statistics?
Why do we backup Active Directory ?
Explain what are the authentication modes in sql server?
How to delete exactly duplicate records from a table?
If I delete a template from the list in sql studio, will it be deleted from the hard disk? : sql server management studio
Can a function call a stored procedure in sql server?
What do you mean by stored techniques? How would we use it?
Why is normalisation important?
What is a partition function in sql server?
How does the report manager work in SSRS?
What happens if null values are involved in datetime operations?
What are parameterized reports?
What is forward - only cursors / read only cursor?
What is difference between count (*) and count 1?
How do I find the sql server instance name?