Monday, August 4, 2008

SQL inline query with input and output parameters

How to build up a query within a stored procedure and get output parameters from it, here's an example...

DECLARE @Value NVARCHAR(50), @Query NVARCHAR(255), @Params NVARCHAR(50)

SET @Query = 'SELECT @Value = 54;'

EXEC sp_executesql @Query, N'@Value int OUTPUT', @Value = @Value OUTPUT

SELECT @Value


You can also feed input parameters if need be...

No comments: