SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Audit transformation in SSIS

Audit transformation in SSIS

Phil Parkin
Phil Parkin
SSC Guru
SSC Guru (129K reputation)SSC Guru (129K reputation)SSC Guru (129K reputation)SSC Guru (129K reputation)SSC Guru (129K reputation)SSC Guru (129K reputation)SSC Guru (129K reputation)SSC Guru (129K reputation)

Group: General Forum Members
Points: 129402 Visits: 22595
daniel-johnsson (3/14/2013)
Hi Phil and Lynn,

I have been trying to solve my problem with your instuctions but I'm still not able to work it out I'm afraid. Maybe I am missing something obvious, so I will explain a bit more in detail how far I have got.

I created an integer variable that I named AuditID and before I do my first load to my first staging table I insert a row in my Audit_table with the following t-sql:

INSERT INTO dbo.STAGE_AUDIT ([Audit ID], [Package Name], [Execution Start Time], [Machine name], [User name], [Task name])
VALUES (1, 'Staging', '2013-03-13', 'DANIEL-SSIS', 'ECUTBILDNING\Administrator', 'Stage Geography')


This way it inserts the same information as my Audit Transformation would. Maybe this is not how the SQL statement should look like, but I'm honestly unsure what the statement should look like.
Nevertheless, I'm successfully loading my variable with 1 in the Result Set section saying result name = 0, Variable name = User::AuditID. Also I'm using result set as single row.

From this Execute SQL Task my data flow continues into my first load Data Flow task which I can summarize like this:
A source where I retieve some data and insert it into my staging table.
Next to it I use the same source, retrieving the same data but before I connect it to my destination I use an Audit Transformation and also a Row Sampling to only have 1 row as the output since they are all identical except for their AuditID. I then connect it to my destination table, which is my Audit_Table.
Lastly I use a source which is my staging table that I loaded previously. My data path is connected with a Derived Column which looks as following:
I replace my audit_id column with the expression audit_id == @User::AuditID and then I connect this Derived Column with my destination, which is the same table as my source.

Sadly when I run this package my AuditID remains NULL in my staging table. Obviously I'm doing something wrong but that is why I'm here asking for help is it not Smile

Thanks again for your time and help, and I'm sorry if it's not very clear with the lack of images and the fact that it's all just text. Let me know if it's unclear or wether you need more information.

// Daniel

First things first, you don't need IDENTITY_INSERT here (otherwise the package will fail the second time you run it). Instead, do this:

INSERT INTO dbo.STAGE_AUDIT ([Package Name], [Execution Start Time], [Machine name], [User name], [Task name])
VALUES ('Staging', '2013-03-13', 'DANIEL-SSIS', 'ECUTBILDNING\Administrator', 'Stage Geography')


That's the whole point of using scope_identity() - it brings back whatever value SQL Server generated during the insert.

Now, on to derived columns. Your Expression will be


(note - no equals signs)

Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.


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