#0281 – SQL Server – T-SQL – Backslash breaks a long string into smaller ones


Today’s post is actually a quick tip about something I learnt over the week-end. We may often have a long line of text that needs to be embedded into our T-SQL code for inserting static data. Depending upon the IDE settings on the client workstation, the long line of text would either automatically wrap-around to a new line or continue in a single line forever, affecting the readability of the entire T-SQL query.


The easiest way to split a long line of text into multiple lines for readability purposes is to use the back-slash character as shown in the script below:

USE tempdb;
GO
DECLARE @stringOperationsTest TABLE (strVale VARCHAR(100));

INSERT INTO @stringOperationsTest (strVale)
VALUES
(‘Microsoft SQL Server’);

SELECT strVale
FROM @stringOperationsTest;
GO

/**********************
RESULTS
**********************/
/*
strVale
———————
Microsoft SQL Server
*/


Until we meet next time,


Be courteous. Drive responsibly.

Advertisements

Let me know what you think about this post by leaving your feedback here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s