November 5, 2002 at 9:58 am
hi,
this is my stored procedure:
CREATE PROCEDURE stp_SelectSQL
(
@sql text,
@Result int OUTPUT
)
AS
DECLARE @OID int
EXEC(@SQL)
SET @Result=@OID
RETURN @Result
GO
and this is en example of query to pass to stored procedure:
SELECT @OID=OID FROM tbBaseProducts WHERE ImpPrKey = '020amm0010'
This is the error message:
Must declare the variable '@OID'. The 'stp_SelectSQL' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.
Help me !!!!!
thanks, anakin
November 5, 2002 at 10:34 am
Try looking at the following topic, I believe it holds your answer.
Far away is close at hand in the images of elsewhere.
Anon.
November 6, 2002 at 11:57 am
So what you need is
DECLARE @OID int
exec sp_executesql @sql, '@OID int OUTPUT',@OID OUTPUT
SET @Result=@OID
RETURN @Result
Be aware that using dyanmic sql means you need to give users writes to the underlying tables, rather than give access to stored procedures.
Simon Sabin
Co-author of SQL Server 2000 XML Distilled
http://www.amazon.co.uk/exec/obidos/ASIN/1904347088
Simon Sabin
SQL Server MVP
http://sqlblogcasts.com/blogs/simons
November 7, 2002 at 10:34 am
Also be careful if you inadvertently pass in an erroneous SQL string (i.e. refering to a field or table that doesn't exist). This may cause the server to ramp up to CPU 100%.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply