SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
DB_Newbie2007
DB_Newbie2007
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1056 Visits: 1346
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! Smile

Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)
Peter Brinkhaus
Peter Brinkhaus
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3099 Visits: 7404
http://msdn.microsoft.com/en-us/library/dd207007(v=sql.105).aspx

If you have BOL installed, just lookup '\' in the index.
Lowell
Lowell
SSC Guru
SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)SSC Guru (71K reputation)

Group: General Forum Members
Points: 71232 Visits: 40930
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!
DB_Newbie2007
DB_Newbie2007
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1056 Visits: 1346
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)
Peter Brinkhaus
Peter Brinkhaus
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3099 Visits: 7404
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.
Rudyx - the Doctor
Rudyx - the Doctor
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10860 Visits: 2503
add me to the 'newly' informed list as well !

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

Regards
Rudy Komacsar
Senior Database Administrator

"Ave Caesar! - Morituri te salutamus."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search