Group: General Forum Members
Last Login: Today @ 1:27 AM
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:
SET IDENTITY_INSERT dbo.STAGE_AUDIT ON
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 :)
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.
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.
When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
I had some words with my wife, and she had some paragraphs with me.