locked
difference between char(13) and char(10) RRS feed

  • Question

  •  

    Hi

     

    I just need to know what's the difference between carriage return char(13) and line feed char(10)  from SQL Server perspective. Currently I am having the same output in the text editor of SQL Server Management Studio in the following example;

     

    select 'a'+char(13)+'b'

    select 'a'+char(10)+'b'

     

     

    Thanks.

    Salman Shehbaz.
    Wednesday, October 29, 2008 10:00 AM

Answers

  • char(13) is carriage return and char(10) is line feed. Different text editors/viewers will interpret it differently. For example, in the SSMS output window, the following 3 does not show any difference.

     

    Code Snippet

    SET NOCOUNT ON

    SELECT 'HI ' + CHAR(13) + 'Jacob'

    SELECT 'HI ' + CHAR(10) + 'Jacob'

    SELECT 'HI ' + CHAR(13) + CHAR(10) + 'Jacob'

    /*

    ---------

    HI

    Jacob

    ---------

    HI

    Jacob

    ----------

    HI

    Jacob

    */

     

     

    But if you copy it to NOTEPAD, you will see that the first two strings are displayed in a single line. A line break is inserted only for the last string.

     

    If you want to generate a line break, it is a good practice to use CR and LF together. CHAR(13) + CHAR(10)

    Wednesday, October 29, 2008 10:37 AM

All replies

  • here is diff .. though both look alike

     

    Control character Value

    Tab

    char(9)

    Line feed

    char(10)

    Carriage return

    char(13)

    • Proposed as answer by SParsa Thursday, November 29, 2012 6:52 AM
    Wednesday, October 29, 2008 10:21 AM
  • char(13) is carriage return and char(10) is line feed. Different text editors/viewers will interpret it differently. For example, in the SSMS output window, the following 3 does not show any difference.

     

    Code Snippet

    SET NOCOUNT ON

    SELECT 'HI ' + CHAR(13) + 'Jacob'

    SELECT 'HI ' + CHAR(10) + 'Jacob'

    SELECT 'HI ' + CHAR(13) + CHAR(10) + 'Jacob'

    /*

    ---------

    HI

    Jacob

    ---------

    HI

    Jacob

    ----------

    HI

    Jacob

    */

     

     

    But if you copy it to NOTEPAD, you will see that the first two strings are displayed in a single line. A line break is inserted only for the last string.

     

    If you want to generate a line break, it is a good practice to use CR and LF together. CHAR(13) + CHAR(10)

    Wednesday, October 29, 2008 10:37 AM
  • Your tip on CHAR(13) + CHAR(10) being used TOGETHER helped me resolve a REPLACE query, since I couldn't tell which character was which prior to your note. Thanks

    UPDATE [TABLENAME]
    SET [COLUMNNAME] = REPLACE(COLUMNNAME,char(10),'')
    WHERE [OTHERCOLUMNNAME] = 'theothercolumnname_value'
    AND [COLUMNNAME] LIKE '%' + CHAR(13) + CHAR(10) + '%';

    Friday, March 9, 2012 7:18 AM
    • Edited by Kalman Toth Thursday, November 9, 2017 12:17 AM
    Friday, March 9, 2012 8:19 AM