• Not necessarily... agreed that 17k 'select' statements is 'brute force', but i would suggest that a simple modification to the original vbs could do all of the work ... and 17k would not be prohibitive for the script below:

    [font="Courier New"] Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Const TristateFalse = 0, TristateTrue = -1, TristateUseDefault = -2

    '---- DataTypeEnum Values ----

    Const adPropVariant = 138:Const adVarNumeric = 139:Const adArray = &H2000:Const adUseClient = 3

    Const adOpenForwardOnly = 0:Const adLockReadOnly = 1:Const adCmdStoredProc = &H0004

    Const adExecuteNoRecords = &H00000080:Const adOpenStatic = 3:Const adCmdText = &H0001

    strFilename = "C:\TEMP\custID.txt "

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFSO.OpenTextFile(strFilename, ForReading)

    ' Read text file line by line

    Do Until objFile.AtEndOfStream

    strLine = strLine & "'" & objFile.ReadLine & "',"

    Loop

    objFile.Close

    strLine = left(strLine, len(strLine)-1) 'KNOCK OFF THE LAST APOS

    strSql = "SET NOCOUNT ON; SELECT C.CustomerID as [CustomerID], C.CompanyName as [CompanyName], " &_

    " C.City as [City], O.OrderDate as [OrderDate], O.Freight as [Freight] FROM Customers C INNER JOIN Orders O " &_

    " ON C.CustomerID = O.CustomerID WHERE C.CustomerID IN (" & strLine & ") ORDER BY C.CustomerID; SET NOCOUNT OFF"

    Wscript.Echo strSql

    DIM rs

    Set rs = GetRecordset( "(local)", "Northwind", strSql )

    IF NOT ISNULL(rs) THEN

    Set objFSOW = CreateObject("Scripting.FileSystemObject")

    Set objFileW = objFSOW.OpenTextFile ("C:\TEMP\custIDResult.txt", ForAppending, True)

    rs.MoveFirst

    do until rs.EOF

    objFileW.WriteLine rs("CustomerID") & "|" & _

    rs("CompanyName") & "|" & _

    rs("City") & "|" & _

    rs("OrderDate") & "|" & _

    rs("Freight")

    rs.MoveNext

    loop

    set rs = nothing

    objFileW.Close

    ELSE

    Wscript.Echo "RECORDSET IS EMPTY.... NO RECORDS TO PROCESS!"

    END IF

    '********************************************************************************

    '

    Function GetRecordset(ByVal TheSqlSvr, ByVal TheDB, ByVal strSQL)

    Dim rs, sConnect

    Set rs = CreateObject("adodb.Recordset")

    rs.CursorLocation = adUseClient

    sConnect ="Provider='SQLOLEDB';Data Source="& TheSqlSvr &";" _

    & "Trusted_Connection=Yes;" _

    & "Initial Catalog=" & TheDB

    rs.Open strSQL, sConnect, adOpenForwardOnly, adLockReadOnly

    Set rs.ActiveConnection = Nothing

    Set GetRecordset = rs

    Wscript.Echo "#Recs " & cstr(rs.RecordCount)

    End Function

    '==============================

    'C:\TEMP\custID.txt

    'ALFKI

    'ANTON

    'AROUT

    'BERGS

    'BOLID

    'BONAP

    'BSBEV

    'CACTU

    'CONSH

    'DOGGY

    'FOLIG

    'FOLKO

    'FRANK

    'FRANR

    'FRANS

    'FURIB

    [/font]