Solved

Append a column to flat file source

Posted on 2009-03-30
6
305 Views
Last Modified: 2013-11-10
Ok, I don't know if I have the most accurate Title for this question, but here goes:

I have a flat file (tab delimited) containing address updates that needs to go to a SQL database.

So, I went ahead and created a Flat File Source and mapped the columns to a OLE DB Data Flow Destination.

Now, in addition to all the colmns in the flat file, say I wanted to map some "static" values to the destination colmns, how would I accomplish this?

For example, I have a column called "Update Source" in the destination table. How would I insert a value in this column if it doesn't exist in the source file without having to create a new column in the source file?
0
Comment
Question by:IUAATech
  • 2
  • 2
  • 2
6 Comments
 
LVL 5

Assisted Solution

by:catherinelouise
catherinelouise earned 200 total points
ID: 24021736
II would first import the flat file data into a "holding table" - this can be a permanant or a temporary table in the database.  

I would then use the 'Execute SQL Task' tool in SSIS to carry out an insert into the final destination, and at the same time it would be possible to set another column to a specific value.  E.g.

INSERT INTO FinalTable (Col1, Col2, Col3, Col4)
SELECT (Col1, Col2, Col3, 'FIXEDVALUE') FROM HoldingTable
0
 

Author Comment

by:IUAATech
ID: 24021786
That sounds like a lot of work :-)

Wonder if it's possible to use the "OLE DB Command" data flow transformation.
0
 

Author Comment

by:IUAATech
ID: 24021867
Thanks for the suggestion. I will try it out.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 5

Expert Comment

by:catherinelouise
ID: 24021949
It really isn't too much work - although I don't deny there may be a smarter way of doing this!

If you import your file into a new table once using the import wizard that will create your 'holding table' for you - from there your SSIS package should:

1. Execute a SQL task that truncates the holding table (assuming you are running this package multiple times)

2. Import your flat file into the holding table (a similar step to the one you described in your question which will map source to destination)

3. Carry out an Insert into your final table from your holding table as I described above




0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 300 total points
ID: 24025047
You can do this in SSIS by using a Dervied Column transformation. This transformation sits in your data flow and adds columns. The new columns may be based on existing columns or variables, or it may be a constant like what you're after.
It just depends on whether you want to do the work in the ETL tool or in the database. I am currently weaning myself off doing work in the database so I can decide whether its really worth the effort of doing all the work in the ETL tool.
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 24025055
For more info on this task, open up the SQL Server help file from the start menu and paste this URL in it:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/sqltut9/html/16389f8a-0484-4c07-ae73-067b30f11e2d.htm
 
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question