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
Can we call stored procedure in view in sql server?
Mention the differences between local and global temporary tables.
What are the different types of indexes?
List the advantages of using stored procedures?
What is triggers and its types?
What do you understand by the analysis services in sql server?
How to convert a unicode strings to non-unicode strings?
How to create a simple table to test triggers in ms sql server?
What does truncate do?
What is log shipping? Can we do logshipping with SQL Server 7.0 ?
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
What are the advantages of user-defined functions over stored procedures in sql server?
What is the size of transaction log file?
Explain what is row_number function?
What are the limitations in ssrs on sql server express edition?