SA0145 : The EOL marker sequence is not the expected {CR}{LF} |
![]() |
The improper use of end-of-line (EOL) characters can lead to issues when managing SQL code across different platforms and tools, affecting interpretation and execution.

In T-SQL code, consistency in using the correct end-of-line character sequence is crucial for maintaining code compatibility across various systems and editing tools. SQL Server typically expects lines to end with a carriage return followed by a line feed ({CR}{LF}). This standard helps ensure that SQL code is interpreted correctly, especially when moved between different environments or when used with various tools and editors.
For example:
1-- Query with inconsistent EOL characters 2SELECT * FROM Employees -- {LF} used instead of {CR}{LF}
Using an incorrect EOL character, like {LF} alone, might lead to parsing errors or unexpected behavior in certain SQL Server environments or tools that rely on the traditional {CR}{LF} sequence. It can also complicate version control and collaboration if team members use different editors with varying EOL defaults.
-
Potential for syntax errors due to incorrect code parsing in some SQL Server contexts.
-
Increased difficulty in maintaining and collaborating on SQL code due to varied behavior across different editors and platforms.

Ensure SQL code compatibility by standardizing the end-of-line characters to the SQL Server expected {CR}{LF} sequence.
Follow these steps to address the issue:
-
Open the SQL file in SQL Server Management Studio (SSMS) or Visual Studio.
-
Navigate to the file menu and select File > Save As….
-
In the Save File As dialog, look for the Save with Encoding… dropdown button next to the Save button.
-
Select Windows (CR LF) for the file’s line endings from the available options.
-
Save the file to apply the correct end-of-line characters.
For example:
1-- Example of corrected EOL characters in a query 2SELECT * FROM Employees;

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.


Design Rules, Code Smells

There is no additional info for this rule.

SQL
1SELECT * 2FROM Table1, 3 Table2 b, 4 (SELECT * 5 FROM Table4c) c 6INNER JOIN Table3 ON Table3.Table4_id = c.id 7INNER JOIN Table5 -- The line ends with 'r' 8INNER JOIN Table6 ON Table6.Table5_id = Table5.id -- The line ends with 'n' 9ON Table3.Table4_id = c.id, 10 Table8 f, -- The line ends with 'r' 11 Table9, 12 (SELECT * FROM Table7) h; |

No violations found.
