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
After removing a table from database, what other related objects have to be dropped explicitly?
What are the different types of stored procedures?
What is the status of services on passive node for failover cluster in sql server? : sql server database administration
How to populate a table in sql server?
What is intellisense?
How to get the definition of a user defined function back?
Can we call stored procedure in trigger?
What is clustered vs nonclustered index?
What is the difference between insensitive and scroll cursor?
What is query processing?
How do I make a resultset scrollable?
how would you improve etl (extract, transform, load) throughput?
What are the pros and cons of putting a scalar function in a queries select list or in the where clause?
What are trace flags?
What are the Advantages of using CTE in sql server?