For Town column I have split the single column into multiple columns if there is any comma values.

Database
Enthusiast

For Town column I have split the single column into multiple columns if there is any comma values.

CityTown
RajasthanAlwar,Laipur,Ajmer,Kota
HaryanaHisar,Jhajjar,Rohtak
MaharastraMumbai,Pune,




Output:

CityTown1Town2Town3Town4
RajasthanAlwarLaipurAjmerKota
HaryanaHisarJhajjarRohtak 
MaharastraMumbaiPune 
1 REPLY
Junior Supporter

Re: For Town column I have split the single column into multiple columns if there is any comma value

Hi.

STRTOK:

 

 BTEQ -- Enter your SQL request or BTEQ command:                                                                                                                                          
SELECT city,  town1, town2, town3, town4 FROM (SELECT 'Rajasthan' City,
                                                       STRTOK('Alwar,Laipur,Ajmer,Kota',',',1) Town1,
                                                       STRTOK('Alwar,Laipur,Ajmer,Kota',',',2) Town2,
                                                       STRTOK('Alwar,Laipur,Ajmer,Kota',',',3) Town3,
                                                       STRTOK('Alwar,Laipur,Ajmer,Kota',',',4) Town4) pre
;
                                                                                                                                                                                          

 *** Query completed. One row found. 5 columns returned.                                                                                                                                  
 *** Total elapsed time was 1 second.                                                                                                                                                     
                                                                                                                                                                                          
City       Town1                    Town2                    Town3                    Town4                                                                                               
---------  -----------------------  -----------------------  -----------------------  -----------------------                                                                             
Rajasthan  Alwar                    Laipur                   Ajmer                    Kota                  

 

HTH.

 

Cheers.

 

Carlos.