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...


need to split a string into seperate values.

eg.

col1 col2
----------
100 - 'a,b,c'
200 - 'a,x,b,d,e'
300 - 'c'

result:
value count
-------------
a - 2
b - 1
c - 2
etc.



need to split a string into seperate values. eg. col1 col2 ---------- 100 - 'a,b,c&..

Answer / gopi muluka

DECLARE @STR VARCHAR(50),
@Char VARCHAR(10),@N INT, @CNT INT
DECLARE @TAB TABLE (VAL VARCHAR(30), CNT INT)

SET @STR='A,B,C,D,E,F,C,A,S,K,C,B'
SET @CHAR=''
SET @N=1
SET @CNT=1
WHILE @N>0
BEGIN
PRINT @STR
SET @CHAR=SUBSTRING(@STR,1,CHARINDEX(',',@STR)-1)
IF NOT EXISTS(SELECT 1 FROM @TAB WHERE VAL=@CHAR)
INSERT @TAB VALUES (@CHAR,@CNT)
SET @STR=SUBSTRING(@STR,CHARINDEX(',',@STR)+1,115)
IF CHARINDEX(@CHAR,@STR)>0
BEGIN
UPDATE @TAB
SET CNT=CNT+1
WHERE VAL=@CHAR
END
SET @N=CHARINDEX(',',@STR)
PRINT @N
END
SELECT * FROM @TAB

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

What is secondary key?

0 Answers  


select 10 from dual; y its showing all the rows with 10?

1 Answers  


How to run sql statements with oracle sql developer?

0 Answers  


select * from emp where sal in(select max(sal) from emp) here there is any limit for in operator how many values accpect ?

2 Answers  


How will you make performance better for application including front end and back

2 Answers   Metric Stream,


How to write a single statement that concatenates the words ?hello? And ?world? And assign it in a variable named greeting?

0 Answers  


how to insert the records in particular position

1 Answers  


Mention what is the function that is used to transfer a pl/sql table log to a database table?

0 Answers  


What types of commands can be executed in sql*plus?

0 Answers  


What is equi join in sql?

0 Answers  


Does a primary key have to be a number?

0 Answers  


What do you know by pl/sql cursors?

0 Answers  


Categories