PRB: Proper Handling of the Escape Sequence \<cr><lf>

Last reviewed: March 7, 1997
Article ID: Q164291
The information in this article applies to:
  • Microsoft SQL Server, version 6.5

SYMPTOMS

Microsoft SQL Server identifies a Transact-SQL command containing the backslash (\) followed by the carriage return (0x0d) and line feed (0x0a) as an escape sequence.

The following example demonstrates the behavior:

   use pubs
   go

   drop table tblTest
   go

   create table tblTest
   (
      strData varchar(30)
   )
   go

   insert into tblTest values ("c:\
   X")
   go

   insert into tblTest values ("c:\\

   X")
   go

   select * from tblTest
   go

   strData
   ------------------------------
   c:X
   c:\
   X

The first insert contains the \<cr><lf> sequence, and when returned from SQL Server, is c:X. The escape sequence is scanned out by the SQL Server.

However, replacing the \<cr><lf> with \\<cr><lf><cr><lf>, as in the second insert, yields the expected results.

CAUSE

SQL Server sees the \<cr><lf> (\ + 0d + 0a) sequence as an escape sequence.

WORKAROUND

To work around this problem, correct the Transact-SQL string, replacing the \<cr><lf> with \\<cr><lf><cr><lf> before sending the query to the SQL Server.


Keywords : SSrvProg kbprg
Version : 6.5
Platform : WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 7, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.