-1

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#

Amen
  • 15
  • 5
  • 2
    CHAR(13)+CHAR(10) : https://stackoverflow.com/questions/31057/how-to-insert-a-line-break-in-a-sql-server-varchar-nvarchar-string – Mitch Wheat Aug 09 '22 at 11:51
  • 2
    I saw you write CHAR(14) which is clearly wrong – Mitch Wheat Aug 09 '22 at 11:53
  • 2
    What does "not working" mean? How are you viewing these select results? – Martin Smith Aug 09 '22 at 11:57
  • 1
    Are you sure it's not working, and not that you don't have retain the CR/LF feature turned off? – Thom A Aug 09 '22 at 11:57
  • 1
    Does this answer your question? [SSMS Results to Grid - CRLF not preserved in copy/paste - any better techniques?](https://stackoverflow.com/questions/2679481/ssms-results-to-grid-crlf-not-preserved-in-copy-paste-any-better-techniques) – Thom A Aug 09 '22 at 11:57
  • Ah "Not in the SQL management environment" means that they are using SSMS but that it is not working there. Not that they are not using that environment! – Martin Smith Aug 09 '22 at 11:58
  • 1
    Both your attempts work fine: [db<>fiddle](https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=8a2af05625df3d85d1e2277934ea1ab3) Note that the first has *2* new lines, due to it being LF/CR *not* CR/LF. – Thom A Aug 09 '22 at 11:59

2 Answers2

0

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.

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51
-1

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

ulisses
  • 1,549
  • 3
  • 37
  • 85