skip to Main Content

example 1

declare @text VARCHAR(100)
SET @text = 'this is the frist line' + CHAR(10)+CHAR(13) + 'Second line'
select @text

example 2

select 'This is line 1.' + CHAR(13)+CHAR(10) + 'This is line 2.'

why is not it working?
Not in the SQL management environment
And not through code in C#

2

Answers


  1. Well, it depends on the output device.

    So, if you use the standard grid output, then you get this:

    enter image description here

    but, if you change the output option from Grid to text, say this:

    enter image description here

    So, now your output is not to some grid control that can’t displacy the cr+lf.

    but, with text output to the sql console, then yes, we now get this:

    enter image description here

    Now you ALSO tagged this as asp.net?

    So, what kind of control on the web page are you sending the markup to????

    If you send the data to a standard asp.net text box – (hopefully set as mutli-line).

    Then once again, it will correctly display the two lines.

    But, if you send that SAME text say to some "div" on the page as innerHTML, then the cr + lf will not work.

    So, it comes down to like most things in life:

    There is a important context here as to were you are sending the resulting data to.

    Send such data to a console or text based output device (like the sql console – set as text), then it works. Sending to the built in SQL grid control? No, it does not work.

    And same goes for sending such data to a web page. It will "depend" on what kind of control you use to render the data.

    Login or Signup to reply.
  2. I try to understand the question.
    So, please, could you try to change/discover the Tools-Options-Quert Result-Result to Grid. To use the result to grid (more easy, just my opinion)
    Could help you?

    https://www.linkedin.com/posts/daniele-scordamaglia-460a78a5_sqlserver-sql-cr-activity-7053663883944701952-G8It?utm_source=share&utm_medium=member_desktop

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search