December 9, 2008 at 6:49 am
I have 2 tables which I am inserting using separate stored procedures:
RawHeader
HeadID INT
FromDate DATETIME
ToDate DATETIME et al
and RawDetail
DetailID INT
HeadID INT
Amount MONEY et al
after inserting the RawDetail I need to INSERT a DayDetail record
DayID INT
HeadID INT
Amount MONEY
now if there is no DayTable record I need to INSERT one
DayID INT
FromDate DATETIME
ToDate DATETIME et al
I wrote a function which takes the HeadID and looks up the DayID
then a stored procedure which INSERTs a Day record if there isn't one
but...
I am having difficulty passing the new DayID out of one stored procedure back to the calling stored procedure
do I - create a TABLE variable and INSERT it in there?
or
create a parameter as OUTPUT?
or
SET the new DayID as RETURN value?
this seems so simple but I spent 2 hours on it yesterday and ended up with a kluge to get it to work
thanks all
December 9, 2008 at 7:10 am
IMO, you should use an output parameter. This is the most efficient method. If you need help getting the output parameter to work, post some code and I'll take a look.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
December 9, 2008 at 7:17 am
Thanks
I used OUTPUT parameters a lot in Oracle so I think I should be able to get it to work
there's always BOL, too
🙂
December 9, 2008 at 7:37 am
Either an output parameter, or a return value, or you could return a one row, one column result.
In any case, I'd recommend OUTPUT parameters as well.
December 9, 2008 at 7:54 am
OUTPUT parameters will do the trick, but they'll only work for single row inserts. If you need to do any batch work, you'll want to look into the OUTPUT clause so that you can capture multiple ID's as they get created.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply