February 13, 2018 at 10:59 pm
Hi
I have a Procedure
CREATE PROCEDURE ReturnValues(
@ReturnValuesID INT OUT
@MemberID INT
@Name VARCHAR(10)
@InsertedDate DATETIME OUT
)
INSERT INTO dbTable(
MemberID
,Name
)
VALUES(
@MemberID
,@Name
)
I want to return the primary key and the Inserted time.
I thought of this
DECLARE @MyTableVar TABLE(
PK INT
,InsertedDt DATETIME
)
INSERT INTO @MyTableVar
OUTPUT inserted.ReturnValuesID, inserted.InsertedDate
But I'm getting this error:he OUTPUT clause cannot be used in an INSERT...EXEC statement.
Is there any better solution or what am I doing wrong?
February 14, 2018 at 1:39 am
If you're using the procedure in an INSERT INTO ... EXEC... Then you need to be very careful. You can't add more resultsets to the procedure, as they're break the insert. Given that, how do you want to return those two columns?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 14, 2018 at 10:23 am
You could do in in a merge however you may want to consider this: ALTER TABLE dbTable ADD DateCreated datetime CONSTRAINT DFdbTableDateCreated DEFAULT GetDate()
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply