Solved

Append a column to flat file source

Posted on 2009-03-30
6
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

707 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