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 get the query of a table in sql server?
What is nolock hint in sql server 2008
How do triggers work?
Define magic tables in sql server?
What is the default Port No on which SQL Server listens?
1)what is the difference between Reinitializing a Subscription and synchronization the subscription? 2)when to use reinitializing ? 3)when to use synchronization? 4)when adding table or deleting a table what to do?(reinz.. or syn) 5)when adding a column what to do?
What are different types of database indexes?
How to create function without parameter in sql server?
what is a mixed extent? : Sql server administration
Explain how you can deploy an SSRS report?
Define tool Manage Statistics in SQL Server 2000 query ?
Describe in brief authentication modes in sql server.
What is lookup override?
List out what other servers you can use with ssrs?
Is foreign key a primary key?