Search code examples
sql-serverexcelssmsexport-to-excel

Copy- paste data from SQL to EXCEL


A very straightforward procedure is too difficult for me now. I wrote a query then copied the data with headers when I pasted into excel it looked messy but now I know what's happening. The address column in my application is a multi-line text box - in sql the column type: varchar(Max). However in the Sql that column is a single line value.. So what happened is that in Excel. It broke the Address field into the way its entered in the application .. Any idea how to fix this.

I tried Replace and found the ASCHI character but again it didn't work.

replace(replace(replace([GP], CHAR(13), ''), CHAR(32), ' '), CHAR(10), ', ')

Example:

Database Table: ID; PK int Identity Name: varchar(5) Address1: varchar(Max) - MultiLine textbox in application Address2: Varchar(MAX)- MultiLine textbox in application Comment: Varchar(MAX)- MultiLine textbox in application

Table in Sql Management Studio

 ID Name    Address1             Address2                        Comment
1   Dave    13 Close Drive, Newcastle, United Kingdom, NW12 8GS 12 Driveway, Newcastle, NW12 8HS    This comment is shown in SQL SERVER Management in one long line ( not in New Line)

Once its copied to Excel:

ID   Name Address1           Address2      Comment
1   Dave   13 Close Drive      12 Driveway, This comment is shown in SQL 

Newcastle, 
United Kingdom,
NW12 8GS
Newcastle, 
NW12 8HS
SERVER Management in one long line ( not in New Line)

Solution

  • Try using Import-Export wizard of SSMS. Dump the data of the table/view into an Excel.