solving sql server problems for millions of dbas and developers since 2006



SQL Server DBA Tips SQL Server Developer Tips SQL Server Business Intelligence Tips SQL Server Career Tips SQL Server Whitepapers SQL Server Tools SQL Server Webcasts SQL Server Questions and Answers SQL Server Questions and Answers


SQL Product Highlight

Idera - SQL safe backup

Idera's SQL safe provides a high-performance backup and recovery solution for Microsoft SQL Server. SQL safe saves money by reducing database backup time by up to 50% over native backups and reducing backup disk space requirements by up to 95%. SQL safe also enables complete "hands-free" automated backup of your entire SQL Server infrastructure and ensures compliance with your organization's backup and recovery policies. From implementations with tens of SQL servers to enterprises with hundreds of servers spread around the globe, SQL safe is the only SQL Server backup and recovery solution that scales to meet the challenge.

Learn more!












Capture database name before Merge in SSIS Data Flow Task

Asked 2/3/2012 11:24:00 AM by Jackie

I am tasked with merging data from three different servers and databases into one server.  I have been asked to capture the database id, database name, server name, and connection string on each table that I merge together.

WITHIN Data Flow Task:

How can I get the database id, database name, server name, and connection string information and put it in a variable and then created derived columns with variables to be added to each table?

I have researched this to no avail.  Yes I can see the sources being used but I would like to capture them in a table if I am running job overnight.  I want to be able to identify the source of each record in a table per the database audit information.

Please help.

 

I need to identify the source db when I am inside the Data Flow

I have a merge join task that joins two server tables together after being sorted, problem is there is no way to determine which records was kept for what server.

Server 1
Database Name: Adventure
Table: Products
Record 1 Tablet 100 qty

Server 2
Database Name: Trails
Table: Products
Record 1 Tablet 100 qty
Record 2 PC 50 qty


-- Get Server Name and database name before executing MERGE JOIN task --

End Results of MERGE JOIN that I would like to see:

Server 3 (final server)
Database: Adventure_Trails
Table: Products:
Record 1 Tablet 100 qty Server 1 Adventure
Record 2 PC 50 qty Server 2 Trails

I want to see the server name and database name after Merge Join

Problem I don't know what task other than Script Component I can use to get this information. I wished Microsoft provide some system variables with this information to make it easy. Machine name doesn't help me because I am connection my data source to other computers and Machine name only returns the name of the computer the SSIS is currently running on.

My first thought is to use Package Configurations - problem there is if I dynamically retrieve my connection manager, there is no way for me to identify the specific server and database name before the process hits the MERGE JOIN task.

Please help!
Post #1245841

 



Answered 2/4/2012 4:22:26 PM by Ray Barley (0) vote answer is useful vote answer is NOT useful

Add the variables that you want to your package then use the Execute SQL Task.  Set the ResultSet General Property of the Excecute SQL Task to SingleRow and specify your query that returns the things you want; e.g.

SELECT DatabaseName = DB_NAME(), ServerName=@@SERVERNAME

Go to the ResultSet page of the Execute SQL Task properties and map your variables to the colums in your select statement.

As far as the connetion string, since it is in a connection manager you can add a script task to assign the connectionstring property to a variable.

It's a shame the Audit data flow transform doesn't proide this information.  It does have a task name which allows you to name your data flow task and easily get that into the data flow.


Answered 2/4/2012 8:29:37 PM by Jeremy Kadlec (0) vote answer is useful vote answer is NOT useful

Jackie,

Did Ray's post answer your question?

Thank you,
Jeremy Kadlec


Answered 2/7/2012 10:01:34 AM by Jackie (0) vote answer is useful vote answer is NOT useful

Ray  I understand what you are saying but can you do this in DATA FLOW task.   in other words if I have 3 different sources that I pulling data from and and I am merging the data together...is there someway to put the dataname name from the source into the table before the merge happens?

I don't want to use a for each loop because I have more than one source and I am doing a merge.

Why doesn't Microsoft put Execute SQL Task in the Data Flow as well.  Or if they are going to provide audit information then add database name and server name per Connection Manager used in the Data Flow.

Anyone have any suggestions?


Answered 2/7/2012 11:30:27 AM by Ray Barley (0) vote answer is useful vote answer is NOT useful

You can add columns to your queries in the data flow; e.g. @@SERVERNAME, DB_NAME(), etc.



Post an Answer

Keep it clean and stay on the subject or we may delete your comment.
Your email address is not published. Required fields are marked with an asterisk (*)

*Name   *Email   Notify for updates
Comments
*Enter Code refresh code


 
Sponsor Information
"Amazing, Amazing, Amazing! SQL doctor is truly one of the most powerful tools I have seen."

SQL Monitor, server monitoring so easy, your boss could do it. Try it online.

SQL Servers keeping you up at night? Contact the Edgewood SQL Server DBAs for a Health Check. Prices start at $995.

Find and Fix SQL issues with Foglight Performance Analysis. Get a free copy.

Join the over million SQL Server Professionals who get their issues resolved daily.

Valuable SQL Server web casts on Performance Tuning, Development, Administration, SSIS and more...


Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | user groups
Some names and products listed are the registered trademarks of their respective owners.


Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com