Avoid Next Line character in SSMS results

Many a time we copy data from SQL Server Management Studio results pane into Excel while preparing reports and analyzing the data. One of the most common problem is handling Next Line characters. These characters disrupts the indentation of data in Excel sheet.

To address this problem all we need to do is replace such characters with space or Semicolon while selecting the data… You just need to replace CHAR(10) and CHAR(13)! I have experienced CHAR(10), CHAR(13), and combination of these two.

-- Example

-- Impacted results:
select 'vijay' as Name, 'Address Line1
Address Line 2' as Address
union
select 'vijred' as Name, 'new Address Line1
vijred Address Line 2' as Address

-- Results with Workaround
select 'vijay' as Name, REPLACE(REPLACE('Address Line1
Address Line 2',CHAR(10),' '),char(13),' ') as Address
union
select 'vijred' as Name, REPLACE(REPLACE('new Address Line1
vijred Address Line 2',CHAR(10),' '),char(13),' ') as Address
go
--

Advertisements
This entry was posted in Productivity, SQL Server, SSMS and tagged , , , , . Bookmark the permalink.

Leave a Reply

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