carriage return

  • Is there a way to insert a carriage return within a line of tSQL, such as for an address:

    a.Address1 + "carriage return"

    + a.Address2

    Thanks!

  • + char(13)

  • + CHAR(13) + CHAR(10) +

    If other strings are NVARCHAR and result must be NVARCHAR you need to use

    + NCHAR(13) + NCHAR(10) +

    _____________
    Code for TallyGenerator

  • this works too, if a bit weird looking:

    declare @cr varchar(2)

    set @cr = '

    '

    ---------------------------------------
    elsasoft.org

  • While it's possible, I wouldn't recommend putting in control chars into your data.

    Eventually, it's very likely it will give you more troubles than joy.

    Should you, by any chance, need to bcp out a column that has a format like

    adress <cr> more adress

    ..it won't work very well, since the <cr> will mess everything up.

    Better to format your adresses after you have retrieved it, than to store stuff like <cr> <lf> <tab> and such with the 'real' data.

    /Kenneth

  • Really appreciate the help. Thanks!

    Sam

  • I have tried the following but the result ignores the carriage return line feed:

    TSQL:

    DECLARE @print_line VARCHAR (30)

    SET @print_line = 'Line 1'+ CHAR(13) + CHAR(10) + 'Line 2'

    SELECT @print_line

    Result:

    Line 1  Line 2

    Any idea as to what I am doing wrong?

    Howard

  • If using QA in SQL 2000, then you need to set your output to text. i.e.

    Tools > Options > Results

    On the dialog box select [Results To Text] on the drop down box

    In SQL 2005

    Query > Results To > Results To Text

    or CTRL + T in the query window


    Everything you can imagine is real.

  • That's why in many Address tables, you have columns for AddressLine1, AddressLine2, etc.

    You'll be better off in the long run if you follow Kenneth's advice.

    ---------------------------------------
    elsasoft.org

  • Thanks to everyone for the answers and advice.

    Howard

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply