• Kenneth.Fisher (1/3/2013)


    RichB (1/3/2013)


    How about using Quotename...?

    SELECT QUOTENAME('o''neil', '''')

    I looked at Quotename when I was writing this but honestly I'm still not sure exactly what it does. I tried it out in this context and couldn't get it to do what I needed it to. I may just have been using it wrong though.

    I agree. Quotename is fine to use in creating a valid sql string for O'Neil, however it doesn't help you (that I can see) in creating an executable string using sp_executesql. All Quotename is trying to do is to create a valid sql string, it does not know you want the command PRINT + a valid sql string all stored as a sql string.