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 / deepak

declare @Str As varchar(100)
declare @StrNew As varchar(100)
-- You can set any string (max 100 len)
set @Str = 'Bhaskar'
set @StrNew = @Str
declare @PrintVal varchar(10)


While @StrNew <> ''
BEGIN
set @StrNew = Replace(@Str, left(@Str, 1), '')
set @PrintVal= (left(@Str,1) + cast((len(@Str)-Len
(@StrNew)) as varchar(5)))
print @PrintVal + ' ' + @StrNew +' ' +@Str
set @Str = @StrNew
END

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

After removing a table from database, what other related objects have to be dropped explicitly?

998


What are the different types of stored procedures?

1066


What is the status of services on passive node for failover cluster in sql server? : sql server database administration

1166


How to populate a table in sql server?

892


What is intellisense?

990


How to get the definition of a user defined function back?

1000


Can we call stored procedure in trigger?

907


What is clustered vs nonclustered index?

884


What is the difference between insensitive and scroll cursor?

1070


What is query processing?

881


How do I make a resultset scrollable?

909


how would you improve etl (extract, transform, load) throughput?

969


What are the pros and cons of putting a scalar function in a queries select list or in the where clause?

1154


What are trace flags?

959


What are the Advantages of using CTE in sql server?

1041