Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Unintended Escape\Continuation Character, BackSlash, in Executed Variable? Expand / Collapse
Author
Message
Posted Wednesday, July 23, 2014 9:57 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 23, 2016 7:17 AM
Points: 200, Visits: 1,319
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)
Post #1595567
Posted Thursday, July 24, 2014 4:51 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, September 18, 2016 11:14 PM
Points: 1,627, Visits: 6,930
http://msdn.microsoft.com/en-us/library/dd207007(v=sql.105).aspx

If you have BOL installed, just lookup '\' in the index.
Post #1595849
Posted Thursday, July 24, 2014 5:07 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:39 AM
Points: 14,469, Visits: 38,083
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!
Post #1595852
Posted Thursday, July 24, 2014 5:55 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 23, 2016 7:17 AM
Points: 200, Visits: 1,319
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)
Post #1595862
Posted Thursday, July 24, 2014 5:59 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, September 18, 2016 11:14 PM
Points: 1,627, Visits: 6,930
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.
Post #1595863
Posted Thursday, July 24, 2014 10:17 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Saturday, September 24, 2016 9:57 AM
Points: 3,243, Visits: 2,465
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."
Post #1595954
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse