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

Define the one-to-one relationship while designing tables.

908


what is bit datatype? : Sql server database administration

924


How can you ensure that the database and sql server based application perform well?

1085


Do you know how to make remote connection in database?

968


Explain about protocol layer present in SQL server?

1211


List the different index configurations possible for a table?

937


How to drop an existing table with "drop table" statements in ms sql server?

1090


How do I create an extended event in sql server?

958


Do you know what is difference between stored procedure and user defined function?

1099


What objects does the fn_my_permissions function reports on? : sql server security

1043


What are two difference between sql azure and azure tables?

159


If any stored procedure is encrypted, then can we see its definition in activity monitor?

994


What is cursor in ms sql server?

1155


What is de-normalization and what are some of the examples of it?

976


Write a sql query to get zero records from a table having n number of records?

1181