Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comments in Code Passed to sp_executesql

Status
Not open for further replies.

Gooser

Technical User
Jun 28, 2006
803
US

[CODE SQL]
SET @newsql_1 = 'INSERT INTO @egbs_1 VALUES ( ' + @newsql_1 + ' )'

EXEC sp_executesql @newsql_1

SELECT * FROM @egbs_1
[/CODE]

This project is just a thorn in my side! Okay, so the code being passed to sp_executesql here, @newsql_1 had an ORDER BY clause in it. Of course, INSERT wants nothing to do with an ORDER BY clause, so I replaced the ORDER BY with '/*' and appended a '*/' to the end of the string. Is it valid to pass comments like this to sp_executesql?

v/r

Gooser

Why do today
that which may not need to be done tomorrow [ponder] --me
 

I tried this and it worked:

Code:
declare @try nvarchar(1000)

set @try = 'Select * from <tablename> /*some comment*/'

exec sp_executesql @try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top