Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Dynamic Destination Field/Column Mapping


Dynamic Destination Field/Column Mapping

Author
Message
SSIS Newbie
SSIS Newbie
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 41
Hi,

Hope somebody can help or point me in the right direction.
I would like to know if it is possible to map destination columns dynamically.
Let me explain:
I have several files to upload with different formats

e.g.
abc.xls as 5 columns (version 1 of the import file)
col1,col2,col3,col4,col5
01/07/2009,Product 1,123.00,12.00,135.00
02/07/2009,Product 2,125.00,13.00,138.00

abc1.xls has 7 columns (version 2 of the import file)
col1,col2,col3,col4,col5,col6,col7
01/07/2009,Product 1,123.00,12.00,1.00,2.00,135.00
02/07/2009,Product 2,125.00,13.00,1.00,2.00,138.00

The destination for both files go to the same table (Table 1) with columns:
Date
Description
Amount
Tax
TotalAmount
RateAmount1
RateAmount2

I have a table that maps the columns with the 2 versions of these files
File OldHeader Index New Header
abc.xls col1 1 Date
abc.xls col2 2 Description
abc.xls col3 3 Amount
abc.xls col4 4 Tax
abc.xls col5 5 TotalAmount
abc1.xls col1 1 Date
abc1.xls col2 2 Description
abc1.xls col3 3 Amount
abc1.xls col4 4 Tax
abc1.xls col5 5 RateAmount1
abc1.xls col6 6 RateAmount2
abc1.xls col7 7 TotalAmount

How can I map the input columns to the output columns
e.g.
col5 destination column is TotalAmount (abc.xls)
col5 destination column is RateAmount1 (abc1.xls)

I know how to get these values, but how do you map them to the destination table?
Is this possible or is it possible to map using the Index column?

Hope this is clear?
Thanks
SSIS Newbie
drew.allen
drew.allen
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5025 Visits: 10629
If you can get those values, then probably the easiest thing to do is to create two calculated columns: one for Total Amount and one for Rate Amount. Populate whichever calculated column is appropriate and have the other be zero (or nothing).

Drew

J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
How to post data/code on a forum to get the best help.
How to Post Performance Problems
Make sure that you include code in the appropriate IFCode tags, e.g. [code=sql]<your code here>[/code]. You can find the IFCode tags under the INSERT options when you are writing a post.
stevefromOZ
stevefromOZ
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: Moderators
Points: 2932 Visits: 3757
Another approach would be to use a for-each loop over the files. Within this you have a dataflow, and within the dataflow you have an excel connection (source) and sql connection (destination). Set the Excel connection to be an expression, also use an expression to set the query from the excel. I'd prob look to alias the column names in that query to the true names in the destination. Doing this, you should get an automapping of columns to the target, by name.

Steve.
SSIS Newbie
SSIS Newbie
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 41
Thanks Steve.

Can the mapping of the columns (alias) be done dynamically via a script or Transformation?
Reason been is that I would be processing lots of different files with different formats.
E.g. abc.xls has 5 col going to SQL table (A), abc1.xls has 7 col going to SQL table (A), bbb.xls has 3 col going to SQL table (B) etc.
I can get the destination into a variable, can I get the alias column names into a variables?

Thanks again.
stevefromOZ
stevefromOZ
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: Moderators
Points: 2932 Visits: 3757
Do you have *any* column names? ie is Col1 a cloumn name that exists in the data, or more a way t convey to use it's the first column?

If you do have column names, then you can use an expression to set the query against the excel spreadsheet, and of course, an expression can be a concatenation of variable values.

Steve.
kranthi_kk1
kranthi_kk1
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 116
Hi,

Could you send me the files and let me try...
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search