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
Define the one-to-one relationship while designing tables.
what is bit datatype? : Sql server database administration
How can you ensure that the database and sql server based application perform well?
Do you know how to make remote connection in database?
Explain about protocol layer present in SQL server?
List the different index configurations possible for a table?
How to drop an existing table with "drop table" statements in ms sql server?
How do I create an extended event in sql server?
Do you know what is difference between stored procedure and user defined function?
What objects does the fn_my_permissions function reports on? : sql server security
What are two difference between sql azure and azure tables?
If any stored procedure is encrypted, then can we see its definition in activity monitor?
What is cursor in ms sql server?
What is de-normalization and what are some of the examples of it?
Write a sql query to get zero records from a table having n number of records?