在SQL查询中使用Excel列中的Where子句 [英] Using Excel Columns in SQL Query for Where Clause

查看:74
本文介绍了在SQL查询中使用Excel列中的Where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT        
    Table1.SourceName, Table2.TableName, Table3.SourceSQL, 
    Table1.SourcePath, Table4.ProcessType
FROM
    Table1 
INNER JOIN
    Table3 ON Table1.SourceID = Table3.SourceID 
INNER JOIN
    Table2 ON Table3.ID = Table2.ID 
INNER JOIN
    Table4 ON Table1.ProcessID = Table4.ProcessID
WHERE        
    Table2.TableName = '[EXCEL COLUMN 1 ROW 1]' 
    OR Table2.TableName = '[EXCEL COLUMN 1 ROW 2]' 
    OR Table2.TableName = '[EXCEL COLUMN 1 ROW 3]' 
    ...OR Table2.TableName = '[EXCEL COLUMN 1 ROW N]';

查询本身不是我的问题-可能存在一些不一致之处,因为我更改了Select和Join语句中的表/行名称.

The query itself is not my question - there may be some inconsistencies because I altered table/row names in the Select and Join statements.

我专注于Where子句-有没有一种方法可以将Excel电子表格中的记录(记录都在同一列中)提取到此查询中,而无需手动写入每个记录.我正在使用MS SQL Server Management Studio 2014.

I'm focused on the Where clause - is there a way I can pull records from an excel spreadsheet (records all in the same column) into this query without writing each one in manually. I'm using MS SQL Server Management Studio 2014.

让我知道是否需要更多信息.

Let me know if more information is needed.

推荐答案

您可以尝试从此处 https://social.msdn.microsoft.com/Forums/sqlserver/zh-CN/3019b4ec-fd3e-41c3-8f2e-cd85dc180ef4/sql-2012-64-bit-linked-server-to-excel-2013-64-bit?forum = transactsql

You could try installing the access database engine from here https://www.microsoft.com/en-us/download/details.aspx?id=13255 and trying to create a linked server to the excel sheet as mentioned here https://social.msdn.microsoft.com/Forums/sqlserver/en-US/3019b4ec-fd3e-41c3-8f2e-cd85dc180ef4/sql-2012-64-bit-linked-server-to-excel-2013-64-bit?forum=transactsql

这篇关于在SQL查询中使用Excel列中的Where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆