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
How to modify the underlying query of an existing view?
What is analysis service repository?
What is the difference between locking and multi-versioning?
Write a program using SQL queries to find a unique entry in a table.
What is dbcc? Give few examples.
Explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?
Explain subquery and state its properties?
What is indexed view?
When would you prefer to have a minimum number of indexes?
What is GUID in sql server?
What is a DBMS, query, SQL?
What is your recommendation for a query running very slow? : sql server database administration
What is data source view or dsv? : sql server analysis services, ssas
What is a mutating table error and how can you get around it?
What is user-defined functions? What are the types of user-defined functions that can be created?