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

Can we call stored procedure in view in sql server?

506


Mention the differences between local and global temporary tables.

575


What are the different types of indexes?

621


List the advantages of using stored procedures?

567


What is triggers and its types?

554






What do you understand by the analysis services in sql server?

546


How to convert a unicode strings to non-unicode strings?

573


How to create a simple table to test triggers in ms sql server?

523


What does truncate do?

539


What is log shipping? Can we do logshipping with SQL Server 7.0 ?

584


Can we make the the chages By Using the Sql if u know any function or process please inform me Actuall result: BRK1 Break 1 Part 1 00:01:00:00 60 BRK1 Break 1 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 BRK2 Break 2 Part 2 00:01:00:00 60 BRK2 Break 2 Part 3 00:01:00:00 60 BRK3 Break 3 Part 1 00:01:00:00 60 BRK3 Break 3 Part 2 00:01:00:00 60 Desired O/P: BRK1 Break 1 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 Part 3 00:01:00:00 60

1726


What are the advantages of user-defined functions over stored procedures in sql server?

472


What is the size of transaction log file?

501


Explain what is row_number function?

577


What are the limitations in ssrs on sql server express edition?

139