Syntax highlighting isn't always present in the entire code block
This is an odd one. I've noticed this in a few languages, not just SQL, but sometimes the highlighting just doesn't work on the entire code block. This appears to happen more when the code snippet isn't complete on its own (and so isn't valid syntax on its own).
Take the below SQL snippet for example:
SUM(CASE WHEN SIPCOD in ('001','500') or (SIPCOD = '013' and SISHCD = 'OTA') THEN 1 ELSE 0 END) -SUM(CASE WHEN SIPCOD in ('501','502') and SIHRS >= 3.0 THEN 0.5 ELSE 0 END) as [Days Worked]
Even with the language defined (both with sql
or lang-sql
), the first line to receive syntax highlighting is the fourth line (END) -
); the prior lines have no highlighting. The image below is from SO Dark Theme:
Image may be NSFW.
Clik here to view.
I'll try and repro this with some other languages and edit it in, or if I see other examples (I'm sure I've seen at least one C# and PowerShell example over the weekend on my mobile).
This is SQL again. However, this one doesn't highlight the last line, for some reason:
IF EXISTS (SELECT 1 FROM [135.282.123.12].tempdb.sys.tables WHERE [name] = N'##Tmp1') PRINT N'YES';ELSE PRINT N'No';
Image may be NSFW.
Clik here to view.
Apologies, this is SQL again, but the highlighting is all kinds of wrong in this code block. It starts, then suddenly stops, and then picks up again it the oddest place:
CREATE TABLE dbo.RealTable (ID int IDENTITY);GODECLARE @SQL nvarchar(MAX);--Good attemptEXEC dbo.CreateNewColumn @TableName = N'RealTable', @ColumnName = N'SomeString', @sql_dtype = N'nvarchar', @length = '255', @SQL = @SQL OUTPUT;PRINT @SQL;--Another good attemptEXEC dbo.CreateNewColumn @TableName = N'RealTable', @ColumnName = N'SomeInt', @sql_dtype = N'int', @SQL = @SQL OUTPUT;PRINT @SQL;GODECLARE @SQL nvarchar(MAX);--A bad attemptEXEC dbo.CreateNewColumn @TableName = N'RealTable', @ColumnName = N'AChar', @sql_dtype = N'char', @length = N'CREATE USER test WITHOUT LOGIN', @SQL = @SQL OUTPUT;PRINT @SQL;GODECLARE @SQL nvarchar(MAX);--Bad parametersEXEC dbo.CreateNewColumn @TableName = N'RealTable', @ColumnName = N'SomeNumeric', @sql_dtype = N'decimal', @length = 7, --This should be precision and scale @SQL = @SQL OUTPUT;GODECLARE @SQL nvarchar(MAX);--Good parametersEXEC dbo.CreateNewColumn @TableName = N'RealTable', @ColumnName = N'SomeNumeric', @sql_dtype = N'numeric', @Precision = 7, --This should be precision and scale @Scale = 2, @SQL = @SQL OUTPUT;SELECT *FROM dbo.RealTable;GODROP PROC dbo.CreateNewColumnDROP TABLE dbo.RealTable