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 the different types of sub-queries?
What is indexing a document?
what do you understand by change data capture?
What is after dml trigger?
How to create an index on an existing table in ms sql server?
Will count(column) include columns with null values in its count?
What is rolap and its advantage? : sql server analysis services, ssas
What is use of attributehierarchyenabled? : sql server analysis services, ssas
How to remove duplicate rows from table except one?
Why use “nolock” in sql server?
Does an index slow down updates on indexed columns?
Define normalisation?
Where does the copy job runs in the log shipping primary or secondary? : sql server database administration
How to change the system date and time from SQL Plus Terminal ?
How to update multiple rows with one update statement in ms sql server?