Problem description:
in the process of work, sometimes encountered such a problem, write a SQL query to query data in the database, see the number of rows (such as 1000 rows), but make a copy of the query results to Excel, but happened mismatch, and lead to Excel in the number of lines is more than 1000 lines, caused the number of rows of data inconsistency.
field value contains char(10) newline character, copy the field value to Excel.
Source:
some corresponding cell contains a newline, lead to dislocation happened in copy to Excel.
Option 1 (Recommended) : Enclose the field values in question in double quotation marks so that the newline characters in the field values are restricted to the correct Excel cell.
scenario 2: use the script to remove the corresponding field value newline character.
create table #t
(
Name nvarchar(50),
Remark nvarchar(50)
)
insert into #t
lues (‘ A1 ‘+ char(10) +’ B1 ‘, ‘row 1’), (‘ A2B2 ‘, ‘row 2’)
select Name, Remark
om #t
— Solution 1: You can put double quotation marks directly in the field, and copy it to Excel without misplacing or showing redundant double quotation marks.
select ‘”‘ + Name + ‘”‘ as Name, Remark
om #t
select replace(replace(Name, char(13), ‘ ‘), char(10), ‘ ‘) as Name, Remark
om #t
drop table #t
Read More:
- How to batch create folders in Excel form and copy the specified files to a new folder
- How to Solve mybatis returns null when querying Oracle database with char type field
- To solve the problem of C # calling excel interface error, prompt: the COM object of Microsoft. Office. Interop. Excel. Applicationclass is forcibly converted to the interface type “Microsoft. Offi”
- Error querying database.Cause:java.sql.SQLSyntaxErrorException:ORA-00911:invalid character
- Use of HQL query.list () is a null pointer exception, but the database can find out the result
- [Python] pandas Library pd.to_ Parameter arrangement and example of Excel operation writing into excel file
- Error attempting to get column ‘xxxxx’ from result set — after Lombok is annotated with builder, mybatis cannot recognize the correct type of field
- Syntax error: unexpected character after line continuation character
- SQL Server calls Database Mail to send mail error: Msg 229, Level 14, State 5, Procedure sp_send_dbmail, Line 1 EXECUTE
- Solving syntax error: unexpected character after line continuation character
- JDBC connect to Sql Server to connect to the database–The TCP/IP connection to the host localhost, port 1433 has failed
- There was a problem sending the command to the program in Excel 2010
- Error attempting to get column time from result set. Cause: java.sql.SQLFe
- How to Fix SQL Error: 1054, SQLState: 42S22 Unknown column ‘markcardex0_.art_service_time’ in ‘field list’
- Solution to the problem of no C / C + + option in the new project of eclipse
- The solution to the problem that the method of interacting with database in the servlet class is invalid after the servlet submits 404, 500 refresh and becomes 404, and after connecting to the data pool
- “No nodes available to run query” is reported when using Presto to connect to MySQL query“
- To solve the problem that windows Remote Desktop Services cannot copy and paste: restart rdpclip.exe
- Mybatis integrates Oracle query and reports an error in the datetime type field
- The problem of MAC switching JDK version and RN Android JDK version leads to compilation failure. Solve it