Recently, I had an interesting situation where my client was inserting multiple texts in their text column but their output was always in a straight line. During the Comprehensive Database Performance Health Check, they asked me questions if I know how to fix it. Well, it is actually very simple and we need to learn about Grid vs Text Output.
Grid vs Text Output
First, let us open the SQL Server Management Studio (SSMS). Whenever we run any query, the query is visible in the results window. There is three option of how the result of the query will be visible. The first option is text, the second is a grid and the third one is a file.
The short cut for each of the mode is as follows:
- Text – CTRL + T
- Grid – CTRL + D
- File – CTRL + SHIFT + F
Now let us run the following code and observe output when the TEXT and GRID output are enabled.
DECLARE @sVar VARCHAR(100) SET @sVar = 'SQL Athority' SELECT @sVar sVar
Here is the output in TEXT as well as GRID format.
It is very clear from the display that the newline feed is not preserved when the output is displayed in the GRID format. However, if you want the data in the same format as it was inserted, you will have to display it in either text or file format.
If you have any further questions, you can reach out to me on Twitter.
Reference: Pinal Dave (https://blog.sqlauthority.com)