Hello Everyone.
I have been given an assignment that has me perplexed.
I am curious if there is a way to get the result set of a dynamic query returned to the calling stored procedure. Since dynamic sql runs in it's own context, I can't just assign variables in the @SqlString. I am open to all suggestions. The code below is just my jump off point.
@TableName is a parameter.
Thanks everyone.
Patrick
I have been given an assignment that has me perplexed.
I am curious if there is a way to get the result set of a dynamic query returned to the calling stored procedure. Since dynamic sql runs in it's own context, I can't just assign variables in the @SqlString. I am open to all suggestions. The code below is just my jump off point.
@TableName is a parameter.
Code:
DECLARE @SqlString NVARCHAR(max)
SET @SqlString = N'
SELECT rt.name, MAX(rt.currentclass) AS MaxClass
FROM ' + @TableName + ' AS rt WITH (NOLOCK)
GROUP BY rt.name
'
Thanks everyone.
Patrick