Sql 如何从文本文件中读取大文件列表以形成查询

Sql 如何从文本文件中读取大文件列表以形成查询,sql,excel,vba,Sql,Excel,Vba,我有这个查询,我必须在excel中运行多次,我需要更改其中的文件列表 select * from files where filename in ('filename1','filename2') 因此,我在TEMP中的查询文件名中有一个TEMP,我想循环并获取所有文件列表的结果。我唯一的问题是将.txt读入TEMP并对txt文件中的所有文件名执行一次查询。我知道如何逐行读取文件,所以这没有帮助 我想从中读取列表的文本文件如下 文件名1 文件名2 . . . . 文件名1

我有这个查询,我必须在excel中运行多次,我需要更改其中的文件列表

   select * from files 
   where 
   filename in ('filename1','filename2')
因此,我在TEMP中的查询文件名中有一个TEMP,我想循环并获取所有文件列表的结果。我唯一的问题是将.txt读入TEMP并对txt文件中的所有文件名执行一次查询。我知道如何逐行读取文件,所以这没有帮助

我想从中读取列表的文本文件如下

文件名1 文件名2 . . . . 文件名15000

是的,一些大数字

    dim filelist as string
    dim filelistpath as string
    sqlstring = "select count(*) from files where  filename in TEMP"
    filelistpath = "c:\"

    open filelistpath for input as #1
    do while not EOF(1)
    line input #1,text
    'here i should construct my file list to replace the TEMP below, how ?
    loop
    close #1 
    sqlstring = replace(sqlstring,TEMP, filelist)

    set rs = conn.execute(sqlstring)

    'here i want to write the result to my excel sheet, how ?

谢谢

我格式化了文本,然后把它作为一个整体来读

Function GetText(sFile As String) As String
   Dim nSourceFile As Integer, sText As String

 ''Close any open text files
  Close

  ''Get the number of the next free text file
   nSourceFile = FreeFile

  ''Write the entire file to sText
   Open sFile For Input As #nSourceFile
   sText = Input$(LOF(1), 1)
   Close

   GetText = sText
   End Function

你的问题很令人困惑。请提供你已经尝试过的代码,这样我们就可以更好地整理你实际正在做的事情。我会很快做这件事,因为它在我的工作中,我在路上。)有没有办法把整个文本文件读入一个变种或什么?