 <p>Well - it returns the query because you told it to do so!</p> <p>Look at your code: you have commented out the line that would actually <strong>execute</strong> the dynamic SQL (<code>EXEC sp_executsql .....</code>), and instead you're returning the query (<code>@QRY</code>) as a string:</p> <pre><code>--EXEC sp_executesql @QRY, '@STR VARCHAR(4000)', @STR RETURN @QRY </code></pre> <p>Just change that to execute the query instead of returning its string representation....</p>