This seems simple...
How do you store a multi-line string so your code stays nicely formatted.
Doing this is ugly
DECLARE @myStr NVARCHAR(MAX)
SET @myStr = 'This represents a really long
string that i need multiple lines for,
dude.'
but the above results in the correct string output:
SELECT @myStr
'This represents a really long string that i need multiple lines for, dude.'
Doing this makes it easier to read my code:
DECLARE @myStr NVARCHAR(MAX)
SET @myStr = 'This represents a really long
string that i need multiple lines for,
dude.'
but results in this:
SELECT @myStr
'This represents a really long string that i need multiple lines for,
dude.'
Is there some special way to escape tabs in a multiline string (like every other language has)..
To leverage this feature, you need to hold down the ALT key, then left click on your mouse to drag the cursor over the text you want to select and type/paste the text you want to insert into multiple lines.
Use triple quotes to create a multiline string It is the simplest method to let a long string split into different lines. You will need to enclose it with a pair of Triple quotes, one at the start and second in the end. Anything inside the enclosing Triple quotes will become part of one multiline string.
-- Using both \r\n SELECT 'First line. \r\nSecond Line. ' AS 'New Line'; -- Using both \n SELECT 'First line.
The "N" prefix stands for National Language in the SQL-92 standard, and is used for representing Unicode characters.
You're looking for a backslash ("\"):
SET @myStr = 'This represents a really long \
string that i need multiple lines for, \
dude.'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With