In SQL Server, I have an existing Document_Add
stored procedure that works and returns a good DocID
value (in Visual Studio vb code) and cannot change. Calling it like this in SQL:
EXEC @DocID = PADS2.dbo.Document_Add @SystemCode...
This runs the stored procedure, but @DocID
is always 0 (whether declared as INT
or varchar
).
Expecting @DocID
to be 2594631 or similar.
Any ideas?
2
Answers
<If this is not the place to follow up, please advise.>
Credit to rjs123431:
SQL SP that ends like this:
Returns a string '2680914' in vb:
But returns 0 when called from SQL like this:
This returns correct DocID (2680914) when using a Temp Table like this:
I always say RTFM – read the fine manual provided by microsoft.
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql?view=sql-server-ver16
Just remember, input and output parameters are scalar, not tables.
If you do need to input of a table look at Example G.
If you execute two SELECT statements in the procedure, you will have MARS (multiple active result sets).
By default, a procedure returns a value of zero. It is typical used to indicate if the procedure was a success. You can code a non zero value to indicate an error.
Always read the docs!