Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert Line break in Case expression result SQL

I have the following Case expression:

SELECT 
    CASE 
       WHEN item = '662627-4' 
          THEN 'KLX Licensed & BOM CONTAINS KLX LICENSED PART(S)'
          ELSE NULL

The result is as follows:

KLX Licensed & BOM CONTAINS KLX LICENSED PART(S)

I would like to have it display like this on two lines:

KLX Licensed &
BOM CONTAINS KLX LICENSED PART(S)`

Is this possible? Is there a character to insert a carriage return in the case statement?

I'm using SQL Server 2016.

like image 696
jmarusiak Avatar asked Jul 26 '26 05:07

jmarusiak


1 Answers

If you are using SSMS: You will not see a difference in the results grid, but you will if you set results to text (shortcut: Ctrl+T).

SELECT CASE WHEN item = '662627-4' THEN 'KLX Licensed & '+char(10)+'BOM CONTAINS KLX LICENSED PART(S)'
           ELSE NULL end

or

SELECT CASE WHEN item = '662627-4' THEN 'KLX Licensed &
BOM CONTAINS KLX LICENSED PART(S)'
           ELSE NULL end

rextester demo: http://rextester.com/YWD92075

like image 67
SqlZim Avatar answered Jul 28 '26 12:07

SqlZim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!