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
What is compound operators?
What do you mean by normalisation?
as a part of your job, what are the dbcc commands that you commonly use for database maintenance? : Sql server database administration
What is the difference between function and stored procedure in sql server?
what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration
What are parameterized reports? What are cascading parameters in ssrs reports?
Where can you find the error log information? : sql server database administration
explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration
How many ways to create table-valued functions?
Is sql server difficult to learn?
System variable and temporary variables
what is normalization? : Sql server database administration
What is cross join in sql server joins?
What is the difference between DataRow.Delete() and DataRow.Remove()?
What are the differences between web role and worker role?