Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Why I am getting this error when renaming a database in ms sql server?

1111


Explain identity in sql server?

1056


What are the types of table?

1031


How many types of built in functions are there in sql server 2012?

970


How do I find the sql server version?

1081


How can I know what locks are running on which resource?

999


what is the difference between openrowset and openquery?

1163


What new changes are being made in SQL Server?

1272


Do you know what are the restrictions applicable while creating views? : SQL Server Architecture

1052


Tell about MOM Tool(Microsoft Operator Manager)?

1963


What is difference between global temporary tables and local temporary tables?

1282


What is the log shipping?

1063


How to use wildcard characters in like operations in ms sql server?

1191


What is the difference between a view and a stored procedure?

1092


How to invoke a trigger on demand?

1153