• pop022 (1/3/2013)


    I know the point you were trying to get across, but using sp_executesql is not needed to print the value of the variable. It could simply be written as follows.

    DECLARE @quotedvar nvarchar(100)

    SET @quotedvar = 'O''Neil'

    PRINT @quotedvar

    Absolutely, but it did make for a simple example of the use of dynamic sql. In fact using sp_executesql is also just an example as you can use EXEC in my examples just as easily.

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]