1

In a stored procedure I'm constructing dynamic SQL which is available in a variable like below:

DECLARE @SqlQry VARCHAR(max) 
SELECT @SqlQry = @SQL  --@SQL has dynamic SQL already.

I can execute this SQL statement like this:

exec (@SqlQry);

My question is how to select and returned results of this execution. I want to return these results just like a normal select statement. Please guide.

1 Answer 1

2

If your statement is a select it will return the dataset as a regular select would.

DECLARE @SqlQry NVARCHAR(max) = 'select wtvr from wtvr'


exec sp_executesql @SqlQry
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.