Solved

Append a column to flat file source

Posted on 2009-03-30
6
303 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Dynamics crm 2011 8 46
how to fix this error 14 48
Extract XML Data from using TSQL 5 32
SQL - Join 2 Tables Based on Ranges 8 10
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now