sql server - SSIS Merge Varying Columns -


using ssis, importing .txt file, part if straight forward.

the file being imported has set amount of columns point, there free text/comments field, can repeat unknown length, similar below.

   "000001","j smith","red","free text here"    "000002","a ball","blue","free text here","but can","continue"    "000003","w white","green","free text here","but can","continue","indefinitely"    "000004","j roley","red","free text here" 

what ideally (within ssis) keep first 3 columns singular columns, merge free-text ones single column. i.e. merge/concatenate appears after 'colour' column.

so when load ssms table, appears like:

000001 | j smith | red   | free text here                                     | 000002 | ball  | blue  | free text here can continue                    | 000003 | w white | green | free text here can continue indefinitely       | 000004 | j roley | red   | free text here                                     | 

i not see easy solution. can try below:

1. load complete raw data temp table (without delimiter):

steps:

  1. create temp table in execute sql task
  2. create data flow task, flat file source (with ragged right format) ,
  3. oledb destination (usint #temp table create in previous task)
  4. set delayvalidation=true connection manager , dft
  5. set retainsameconnection=true connection manager

refer this create temp table , using it.

2. create t-sql separate 3 columns (something below)

with col1 (   select    [val],   substring([val], 1 ,charindex(',', [val]) - 1) col1,   len(substring([val], 1 ,charindex(',', [val]))) + 1 col1len   #temp ), col2 (   select    [val],   col1,   substring([val], col1len, charindex(',', [val], col1len) - col1len) col2,   charindex(',', [val], col1len) + 1 col2len    col1 ) select col1, col2, substring([val], col2len, 200) col3 col2 

t-sql output:

col1    col2    col3 "000001"    "j smith"   "red","free text here" "000002"    "a ball"    "blue","free text here","but can","continue" "000003"    "w white"   "green","free text here","but can","continue","indefinitely" 

3. use above query in oledb source in different data flow task

replace double quotes (") per requirement.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -