How to Insert Line Break in SQL Server String? – Interview Question of the Week #139

Question: How to Insert Line Break in SQL Server String?

Answer: I personally prefer that SQL Server does not deal with string operations, as SQL language is honestly made for relational operations. However, now as we have this question presented in front us, let us let us try to answer it.

How to Insert Line Break in SQL Server String? - Interview Question of the Week #139 linebreak0-800x245

In SQL Server, just inserting a line break in SQL queries will show a line break.

There is no way to explain this so I am going to show you an image which describes how it works.

How to Insert Line Break in SQL Server String? - Interview Question of the Week #139 linebreak1

It is clear from the image that in SQL Server we do not have to insert any special character between line string.

However, to simulate this in SQL Server Management Studio, you need to enable your results in the text format (instead of grid format).

Well, with that said there is another alternative way where we can insert CHAR(13) in the line and it will also demonstrate the result.

Here is the screenshot of that particular code and it will be now clear how to insert a line break in SQL Server.

How to Insert Line Break in SQL Server String? - Interview Question of the Week #139 linebreak2

I personally prefer either of this method as needed by my application. There are some situations where I use the first method and there are some situations where I use the second method.

Which one of the above is your favorite method?

Reference: Pinal Dave (https://blog.sqlauthority.com)

SQL Function, SQL Scripts, SQL Server, SQL String
Previous Post
What does Keyword STATS Indicates in Backup Scripts in SQL Server? – Interview Question of the Week #138
Next Post
How to Create Temp Table From Stored Procedure? – Interview Question of the Week #140

Related Posts

Leave a Reply