简体   繁体   English

格式化Excel查询数据的简便方法

[英]Easier Way to Format Excel Data For SQL query

I often receive requests to query a SQL Server database based on data that is sent to me in an Excel spreadsheet. 我经常收到基于Excel电子表格中发送给我的数据查询SQL Server数据库的请求。

I am looking for a more efficient way of completing these types of requests than my current setup: 我正在寻找一种比当前设置更有效的方式来完成这些类型的请求:

Currently in order to complete the request I do the following: 当前,为了完成请求,我执行以下操作:

Copy the Excel column containing the data that will eventually be placed in a WHERE clause. 复制包含将最终放置在WHERE子句中的数据的Excel列。

Paste the data as text only into Microsoft Word. 将数据仅作为文本粘贴到Microsoft Word中。

Do a find for each paragraph marker and replace it with ', ' 查找每个段落标记,并将其替换为“,”

Then surround the entire clause with parenthesis to enter into an IN clause. 然后用括号将整个子句括起来以输入IN子句。

Does anyone have a suggestion for a more efficient way of accomplishing the same task? 有没有人建议采用更有效的方式来完成同一任务?

Here are a couple of ways: 这有两种方法:

Query the excel spreadsheet directly : 直接查询Excel电子表格

SELECT * 
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\excelfile.xls', [Sheet1$])

Use excel to format the data : 使用excel格式化数据

In next empty column = A1 & "," then copy-down, or ="'"&A1&"'," 在下一个空列中= A1 & ","然后向下复制,或者="'"&A1&"',"

您可以将excell保存为CSV逗号分隔文件,然后从那里开始,但是如果这是正常的事情,我可能会设置一个SSIS流程来为您完成所有操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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