Unintended Escape\Continuation Character, BackSlash, in Executed Variable?

  • I was trying to see if there is any documentation regarding the backslash symbol "\" as a escape or continuation character and have not found anything yet.

    Here is an example:

    DECLARE @Statement varchar(MAX), @Statement1 varchar(MAX);

    SET @Statement = 'SELECT top 10 * from dbo.MyTable -- This is a test \

    WHERE MyValue is not null';

    SET @Statement1 = 'SELECT top 10 * from dbo.MyTable -- This is a test

    WHERE MyValue is not null';

    PRINT @Statement;

    PRINT @Statement1;

    The results:

    SELECT top 10 * from dbo.MyTable -- This is a test WHERE MyValue is not null

    SELECT top 10 * from dbo.MyTable -- This is a test

    WHERE MyValue is not null

    You can imagine my surprise then this type of statement was "executed", i.e.,

    EXEC (@Statement);

    EXEC (@Statement1);

    I can only assume that I "fat fingered" the \ symbol when trying to hit the ENTER button... while this is a simple example, my actual code was 2000 lines long.

    Has anyone seen this before? Any documentation out there?

    Thanks! 🙂

    Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)

  • http://msdn.microsoft.com/en-us/library/dd207007(v=sql.105).aspx

    If you have BOL installed, just lookup '\' in the index.

  • I had never trippeed over this before either; it's good to know.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Peter Brinkhaus (7/24/2014)


    http://msdn.microsoft.com/en-us/library/dd207007(v=sql.105).aspx

    If you have BOL installed, just lookup '\' in the index.

    Peter, thanks for the link. Honestly, this is one case I never would have thought about checking BOL (and I was in BOL twice yesterday)... I figured it was a bug or some weird anomaly! LOL

    Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)

  • According to the 2014 documentation (http://msdn.microsoft.com/en-us/library/dd207007.aspx) this feature was added in SQL 2008. I didn't know of this feature either.

  • add me to the 'newly' informed list as well !

    (I guess Microsoft took the hint from Unix kind of like the 'more' command)

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply