简体   繁体   中英

Excel adds an extra row when transferring T SQL server results from a ntext column

The QS column in my database is of type ntext . Why when I transfer the following query results to Excel 2010, I get extra rows.

Here is my query:

select qn, replace(ltrim(rtrim(cast(qs as nvarchar(max)))),'  ',' ')
from qry
where qn like ('Credit Deficient %')

This is how it looks like in SQL Server 2012 query result window:

LIST STU SC GR LN FN CC BY SC IF CC < 70  AND GR = 10 AND SC < 11

Excel, however, splits across two rows as:

 LIST STU SC GR LN FN CC BY SC IF CC < 70  AND GR

and:

 = 10 AND SC < 11   

Please advise how to update my output into a single row in Excel.

Try this. It will replace a line feed (char(10)) and carriage returns (char(13)) with a space.

select qn, replace(replace(replace(ltrim(rtrim(cast(qs as nvarchar(max)))),'  ',' '), char(13), ' '), char(10), ' ')
from qry
where qn like ('Credit Deficient %')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM