What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 149 Stack Exchange communities.

This is quite similar to SEDE Sql Highlighter is borked for aliases with single quotes which was apparently fixed in 2010. Mine is slightly different. If you look at my answer to http://stackoverflow.com/questions/9507404/sql-server-2005-database-dropped-how-to-find-out-who-did-it-when-it-happened you can see a similar issue, where delimited strings are not properly interpreted, and everything after is considered part of the string.

DECLARE @FileName VARCHAR(255)  

SELECT @FileName = SUBSTRING(path, 0, 
    LEN(path)-CHARINDEX('\', REVERSE(path))+1) + '\Log.trc' --'
  FROM sys.traces WHERE is_default = 1;  

SELECT TOP 1 LoginName, HostName, ApplicationName, StartTime, TextData
  FROM sys.fn_trace_gettable( @FileName, DEFAULT ) AS gt  
  WHERE EventClass = 47 AND DatabaseName = 'splunge'
  ORDER BY StartTime DESC;

I added a comment to the end of that line with a single apostrophe to avoid the rest of the code from appearing as a string, but mods please feel free to edit my answer by removing the comment to see the difference. I assume The '\' in the string treats the \ as an escape character.

Not a major annoyance but the color coding is extremely useful and makes the code readable.

share|improve this question
Did you mean to post this on Stackoverflow.com? –  CoffeeRain Feb 29 '12 at 23:29
No, my question is about how the code editor works and incorrectly interprets a single quote as a part of the string instead of as a delimiter. Why would I post a potential bug about stack overflow to stack overflow? –  Aaron Bertrand Feb 29 '12 at 23:31
The problem is that, even if you write '\\', the first backslash doesn't escape the second. The behavior should depend from the language: In PHP, '\' would effectively escape the string delimiter, but that is not true in all the languages. (I am not sure it is so with all the SQL dialects.) –  kiamlaluno Mar 1 '12 at 1:43
This is certainly not how it works in Transact-SQL. Perhaps we need more specific dialects than <!-- language: lang-sql -->? –  Aaron Bertrand May 31 '12 at 15:18

You must log in to answer this question.

Browse other questions tagged .