SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help in spliting comma delimited column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nasman
Starting Member

15 Posts

Posted - 05/17/2012 :  04:49:38  Show Profile  Reply with Quote
Hi SQL Peeps,

I need help on this, i just need to split a comma delimited column into 2 seperate column and in the same row, is this possible? im extracting this data on a csv file,

**my extracted data looks like this

COL1_OPERATOR COL2_SALES PROMO_ID
------------- ---------- --------
>= or =< 200,500 123


**the raw file looks like this

"COL1_OPERATOR","COL2_SALES","PROMO_ID"
">=or=<","200,500","123"


**The desired result looks like this

COL1_OPERATOR COL2_SALES1 COL2_SALES2 PROMO_ID
------------- ---------- ----------- --------
>= or =< 200 500 123


any help or suggestion is much appreciated

cheers

vijays3
Constraint Violating Yak Guru

India
311 Posts

Posted - 05/17/2012 :  07:34:21  Show Profile  Reply with Quote
Did you try something to achieve this?

Vijay is here to learn something from you guys.
Go to Top of Page

vijays3
Constraint Violating Yak Guru

India
311 Posts

Posted - 05/17/2012 :  07:44:42  Show Profile  Reply with Quote


As records are in comma separated so you can SSIS packages to load the data in you destination table. But make sure for "COL2_SALES" in your raw file should be two values separated with commas.

One more approach: 


create table data (COL1_OPERATOR varchar(20),COL1_SALES1 varchar(20),
COL2_SALES2 varchar(20),
 PROMO_ID varchar(20))

bulk insert data from 'C:\SSISLoad\Data.txt'
with( DATAFILETYPE = 'char',
       rowterminator= '\n',
       Fieldterminator =',')


update data set COL1_OPERATOR = REPLACE(COL1_OPERATOR,'"',''),
                 COL1_SALES1 =REPLACE(COL1_SALES1,'"',''),
                  COL2_SALES2=REPLACE(COL2_SALES2,'"',''),
                   PROMO_ID= REPLACE(PROMO_ID,'"','')
                   
                   
select * from data




Vijay is here to learn something from you guys.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 05/19/2012 :  15:14:24  Show Profile  Reply with Quote
why not use format file and give correct column delimiter?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000