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

How to modify the underlying query of an existing view?

970


What is analysis service repository?

1008


What is the difference between locking and multi-versioning?

971


Write a program using SQL queries to find a unique entry in a table.

973


What is dbcc? Give few examples.

1008


Explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?

1146


Explain subquery and state its properties?

1018


What is indexed view?

963


When would you prefer to have a minimum number of indexes?

879


What is GUID in sql server?

1144


What is a DBMS, query, SQL?

1029


What is your recommendation for a query running very slow? : sql server database administration

1025


What is data source view or dsv? : sql server analysis services, ssas

981


What is a mutating table error and how can you get around it?

1025


What is user-defined functions? What are the types of user-defined functions that can be created?

1017