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 / pradyumna
declare @temp table
(name char(1),counter int)
declare @str varchar(10)
set @str='bhaskar'
declare @strlen int
set @strlen=len(@str)
declare @ctr int
set @ctr=1
declare @Alpha char(1)
while @ctr<=@strlen
begin
set @alpha=substring(@str,@ctr,@strlen-(@strlen-
@ctr))
if not exists (select 1 from @temp where name=@alpha)
begin
insert into @temp values(@alpha,1)
end
else
begin
update @temp set counter=counter+1 where name=@alpha
end
set @ctr=@ctr+1
end
select * from @temp
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Why I am getting this error when renaming a database in ms sql server?
Explain identity in sql server?
What are the types of table?
How many types of built in functions are there in sql server 2012?
How do I find the sql server version?
How can I know what locks are running on which resource?
what is the difference between openrowset and openquery?
What new changes are being made in SQL Server?
Do you know what are the restrictions applicable while creating views? : SQL Server Architecture
Tell about MOM Tool(Microsoft Operator Manager)?
What is difference between global temporary tables and local temporary tables?
What is the log shipping?
How to use wildcard characters in like operations in ms sql server?
What is the difference between a view and a stored procedure?
How to invoke a trigger on demand?