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

What are the different types of sub-queries?

1043


What is indexing a document?

1032


what do you understand by change data capture?

1018


What is after dml trigger?

1016


How to create an index on an existing table in ms sql server?

980


Will count(column) include columns with null values in its count?

1093


What is rolap and its advantage? : sql server analysis services, ssas

1283


What is use of attributehierarchyenabled? : sql server analysis services, ssas

1242


How to remove duplicate rows from table except one?

1007


Why use “nolock” in sql server?

1058


Does an index slow down updates on indexed columns?

972


Define normalisation?

1114


Where does the copy job runs in the log shipping primary or secondary? : sql server database administration

1043


How to change the system date and time from SQL Plus Terminal ?

1220


How to update multiple rows with one update statement in ms sql server?

1203