Solve the problem of line break in the content copied from SQL Server to Excel

Phenomenon: When the result set queried from SQL is copied to EXCEL, line breaks are found, as follows:
insert image description here
insert image description here
Solution: replace the character strings with Char(13) and Char(10), the code is as follows:

--原sql
SELECT Description'事由',DestinationLocation '第三层',BudgetTargetDetailID '第二层',Name'第一层' FROM dbo.BIZ_FIN_Payment(NOLOCK) 
--替换后
SELECT REPLACE(REPLACE(Description,CHAR(10),' '),CHAR(13),' ')'事由',
   REPLACE(REPLACE(DestinationLocation,CHAR(10),' '),CHAR(13),' ') '第三层',REPLACE(REPLACE(BudgetTargetDetailID,CHAR(10),' '),CHAR(13),' ') '第二层',
   REPLACE(REPLACE(Name,CHAR(10),' '),CHAR(13),' ')'第一层'
    FROM dbo.BIZ_FIN_Payment(NOLOCK) a 

Effect after replacement:
insert image description here

Guess you like

Origin blog.csdn.net/vaecnfeilong/article/details/125522617