September 16, 2010 at 9:33 am
I have a procedure that selects records from one table to another, depending on the error flag, Int, 1 or 0.
The procedure is defined as:
Create Procedure InsertInstMain(@JobKey Int, @Rows Int Output, @Errors Int Output)
As
I am trying to populate the 2 output variables defined in the procedure create statement. I have tried both of the following statements, with and without Set NoCount On
Set @Rows = @@RowCount
Select @Rows = Count(*) From InstRaw Where Error = 0 And JobTableKey = @jobkey
I do the same thing with the errors, which are inserted into another table, if some fields fail data validation.
Problem is no values are returned from my procedure. I am beginning to think this is impossible, but perhaps I am not holding my mouth right. If I have NoCount Off I do get information back, in the form of "695,347 row(s) affected", when running in SSMS.
This procedure will be called from an SSIS package once I get it working correctly.
Thanks,
Chris
Learning something new on every visit to SSC. Hoping to pass it on to someone else.
September 16, 2010 at 10:02 am
It's probably how you are calling the sp. Try this in a query window:
alter Procedure InsertInstMain(@JobKey Int, @Rows Int Output, @Errors Int Output)
As
SET NOCOUNT ON
--I am trying to populate the 2 output variables defined in the procedure create statement.
--I have tried both of the following statements, with and without Set NoCount On
SELECT [Today] = GETDATE()
SET @Rows = @@RowCount
SET @Errors = 999
RETURN 0
GO
DECLARE @jobkey Int, @Rows Int, @Errors Int
EXEC InsertInstMain @jobkey, @Rows OUTPUT, @Errors OUTPUT
SELECT [Rows] = @Rows, [Errors] = @Errors
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 16, 2010 at 11:37 am
That works nice. I guess I needed to specify Output when I call the proc. That works better.
Thanks,
Chris
Learning something new on every visit to SSC. Hoping to pass it on to someone else.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply