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


Please Help Members By Posting Answers For Below Questions

What is compound operators?

536


What do you mean by normalisation?

493


as a part of your job, what are the dbcc commands that you commonly use for database maintenance? : Sql server database administration

482


What is the difference between function and stored procedure in sql server?

478


what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration

521






What are parameterized reports? What are cascading parameters in ssrs reports?

100


Where can you find the error log information? : sql server database administration

557


explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration

498


How many ways to create table-valued functions?

571


Is sql server difficult to learn?

511


System variable and temporary variables

1700


what is normalization? : Sql server database administration

520


What is cross join in sql server joins?

582


What is the difference between DataRow.Delete() and DataRow.Remove()?

714


What are the differences between web role and worker role?

98