Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SSIS ExecSQL task - get id from inserted row
Message
From
21/05/2012 14:11:56
 
General information
Forum:
Microsoft SQL Server
Category:
Business Intelligence
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01543953
Message ID:
01543962
Views:
38
>>I have a table [FCA_Batch] that will have a new batch row every time I process a feed that comes in as CSV and I insert into a SQL Table [FCA_staging]
>>
>>Every row inserted into FCA_Staging will get the FCA_Batch_id of the row craeted to store metadata about that process.
>>
>>I want to create the new row in FCA_Batch with Execute SQL Task. My SQL is
>>
>>INSERT INTO [CA_BackFeed].[dbo].[FCA_Batch]
>> ([Process_datetime])
>> VALUES
>> (getdate())
>>GO
>>
>>SELECT ident_current('FCA_Batch')
>>
>>I have ResultSet = Single row and on the result set tab
>>
>>Resultname = NewID var name = User::BatchID
>>
>>But when I execute I am getting
>>
>>Error: No result rowset is associated with the execution of this query.
>>[Execute SQL Task] Error: An error occurred while assigning a value to variable "BatchID": "Exception from HRESULT: 0xC0015005".
>>
>>Obviously I'm missing something. I'm sure this matter of creating a "header" row before creating the "child" rows is not uncommon so any suggestion on how to fix this or for an alternative best-practice implementation greatly appreciated.
>>
>>TIA
>
>I suggest to change the above to
>
>INSERT INTO [CA_BackFeed].[dbo].[FCA_Batch]
>([Process_datetime])
>OUTPUT Inserted.BatchID
>SELECT getdate()
>GO


Wow. Thank you . That did it but now I need to know why?

The OUTPUT Inserted.(fieldname) is new to me, though I think I have seen the Insert used it in some of Denis's triggers.

So this means a lot of places I used IDENT_CURRENT or something similar I could have used this to return the new PK from an SP?

Does this return the PK, the column with the name specified or what?
And why is it before the SELECT getdate()?

And why use SELECT for the getddate()?

If this is basic stuff I should know just point me in whatever direction in BOL

But in the meantime, thanks a lot for giving me a trick that will come in very handy


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform