Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 11:59 AM
Points: 189, Visits: 1,207
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: Thursday, December 18, 2014 10:09 PM
Points: 1,602, Visits: 6,673
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 @ 9:31 AM
Points: 12,962, Visits: 32,501
I had never trippeed over this before either; it's good to know.

Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1595852
Posted Thursday, July 24, 2014 5:55 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 11:59 AM
Points: 189, Visits: 1,207
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: Thursday, December 18, 2014 10:09 PM
Points: 1,602, Visits: 6,673
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: 2 days ago @ 3:44 PM
Points: 3,221, Visits: 2,375
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