Accessing value from dynamic SQL

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dave (davefrick_at_newsgroup.nospam)
Date: 08/04/04


Date: Wed, 4 Aug 2004 16:02:04 -0700

I need to access the value of dynamic SQL statement within a stored proc.

Something like this...

DECLARE @z int
DECLARE @t varchar(10)

SELECT @t = 'authors'

SELECT @z=EXEC('DECLARE @c int
 SELECT @c = Count(*)
 FROM ' + @t + '
 SELECT @c')

The dynamic statement will execute and return a value. But how do I access
this value to use within my proc (i.e., how do I assign the return value of
the dynamic statement to @z)?



Relevant Pages