﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Roy Carlson / Article Discussions / Article Discussions by Author  / Running a Query Using a Text File for Input / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 22:57:24 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Anatol,I used your method to prepare text input to use in a WHERE clause with an IN ( ) list.  If I have a lot more data to input, I would want to use a file for input, but I don't know how to actually use the file that is created in your example.  Please explain.Thanks.</description><pubDate>Wed, 24 Jun 2009 17:34:57 GMT</pubDate><dc:creator>Jay Tucker</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Hi I am new to SQL servers and I would like to know how does one script a database and what is scripting. I know how to use the copy tables but I don't want to copy tables only, I would like to copy the entire database.Thank You</description><pubDate>Tue, 04 Mar 2008 14:29:28 GMT</pubDate><dc:creator>barbichaf2000</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>[quote][b]mojo (1/14/2008)[/b][hr]Does anyone know the Microsoft.Jet.OLEDB.4.0 engine works with 64-bit SQL 2005 server?[/quote]See thishttp://sqlblogcasts.com/blogs/simons/archive/2006/01/05/SSIS-64-Bit_2C00_-Excel-and-Access.aspxIt has a link to another post where more details are discussed. ;)</description><pubDate>Fri, 18 Jan 2008 13:26:31 GMT</pubDate><dc:creator>Philippe Cand</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Very good comprehensive article.  I just don't understand why a simple BULK INSERT couldn't be used to populate a temp table...</description><pubDate>Fri, 18 Jan 2008 10:57:19 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>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"]  [size="2"] Const ForReading = 1, ForWriting = 2, ForAppending = 8   Const TristateFalse = 0, TristateTrue = -1, TristateUseDefault = -2      '---- DataTypeEnum Values ----   Const adPropVariant = 138:Const adVarNumeric = 139:Const adArray = &amp;H2000:Const adUseClient = 3   Const adOpenForwardOnly = 0:Const adLockReadOnly = 1:Const adCmdStoredProc = &amp;H0004   Const adExecuteNoRecords = &amp;H00000080:Const adOpenStatic = 3:Const adCmdText = &amp;H0001strFilename = "C:\TEMP\custID.txt "Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile(strFilename, ForReading)' Read text file line by lineDo Until objFile.AtEndOfStream  strLine = strLine &amp; "'" &amp; objFile.ReadLine &amp; "',"LoopobjFile.ClosestrLine = left(strLine, len(strLine)-1) 'KNOCK OFF THE LAST APOSstrSql = "SET NOCOUNT ON; SELECT C.CustomerID as [CustomerID], C.CompanyName as [CompanyName], " &amp;_   " C.City as [City], O.OrderDate as [OrderDate], O.Freight as [Freight] FROM Customers C INNER JOIN Orders  O " &amp;_   " ON C.CustomerID = O.CustomerID WHERE C.CustomerID IN (" &amp; strLine &amp; ") ORDER BY C.CustomerID; SET NOCOUNT OFF"Wscript.Echo strSql DIM rsSet 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")  &amp; "|" &amp; _                       rs("CompanyName") &amp; "|" &amp; _                       rs("City")        &amp; "|" &amp; _                       rs("OrderDate")   &amp; "|" &amp; _                       rs("Freight")     rs.MoveNext  loop  set rs = nothing  objFileW.CloseELSE  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="&amp; TheSqlSvr &amp;";" _      &amp; "Trusted_Connection=Yes;" _      &amp; "Initial Catalog=" &amp; TheDB  rs.Open strSQL, sConnect, adOpenForwardOnly, adLockReadOnly  Set rs.ActiveConnection = Nothing  Set GetRecordset = rs  Wscript.Echo "#Recs " &amp; 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[/size][/font]</description><pubDate>Fri, 18 Jan 2008 10:08:11 GMT</pubDate><dc:creator>KDM8943</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Does anyone know the Microsoft.Jet.OLEDB.4.0 engine works with 64-bit SQL 2005 server?I got this error when accessing a text file using OPENDATASOURCE with Microsoft.Jet.OLEDB.4.0 as the provider:Msg 7403, Level 16, State 1, Line 1The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered.</description><pubDate>Mon, 14 Jan 2008 12:51:31 GMT</pubDate><dc:creator>mojo-168709</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Thanks Paul,I suspected as much.  Anyway, I've used your excellent post to do what I needed and you've probably saved me many hours of trawling through t'internet to find what I was looking for. REALLY appreciated!</description><pubDate>Tue, 13 Nov 2007 07:01:00 GMT</pubDate><dc:creator>sho-467341</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>I'm not aware of that possibility. You can remove the schema.ini file, but the sequence of the columns becomes arbitrary, to say the least! And doing that may introduce other limitations.</description><pubDate>Tue, 13 Nov 2007 05:59:46 GMT</pubDate><dc:creator>Paul Thornett</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Paul,Thank you very much for posting that example!It works a treat!Is there anyway of doing away with the Schema.Ini file and specifying the rules (ie tab delimited and line feed etc directly in the query as you can with BULK INSERT?)Cheers</description><pubDate>Tue, 13 Nov 2007 03:45:18 GMT</pubDate><dc:creator>sho-467341</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;How about using SQL2005 express on my PC (local installation), use DTS to import the customer ID into a new table then T-SQL join the customer ID table to the linked db in SSM (provided that the db is linkable)?&lt;/P&gt;&lt;P&gt;Is there any problem or disadvantage doing it in this way?&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Sat, 03 Mar 2007 00:43:00 GMT</pubDate><dc:creator>R Wong</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It would have been good to mention that in SQL 2005, you can achieve the same result much more easilly by using a simple Merge Join Data flow transformation. &lt;img src='images/emotions/wow.gif' height='20' width='20' border='0' title='Wow' align='absmiddle'&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Fri, 02 Mar 2007 10:38:00 GMT</pubDate><dc:creator>Philippe Cand</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Very comprehensive. Cheers Paul. &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;</description><pubDate>Fri, 02 Mar 2007 03:48:00 GMT</pubDate><dc:creator>Predrag Miletic</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>1) Create your text folder on the server, e.g. D:\Mssql\LinkedServer2) Populate your text folder. For a simple example, I'm going to use the following tab-delimited file, called Example.txtMyCol1(TAB)MyCol2(TAB)MyCol312138(TAB)129(TAB)Row 1 description12138(TAB)129(TAB)Row 2 description12165(TAB)133(TAB)Row 3 description12212(TAB)134(TAB)Row 4 description12243(TAB)140(TAB)Row 5 description3) Create a Schema.ini file in the same folder. This file is used to describe all the text files you want to refer to.At the very least, it contains the following lines for each filename:[MyExample.txt]CharacterSet=OEMColNameHeader=TrueFormat=TabDelimited   But I find it better to describe each column, as in:[MyExample.txt]CharacterSet=OEMColNameHeader=TrueFormat=TabDelimitedCol1=NamedCol1 LongCol2=NamedCol2 LongCol3=NamedCol3 Text Width 502) Add the linked serverexec sp_addlinkedserver ServerName, 'Jet 4.0', 'Microsoft.Jet.OLEDB.4.0', 'FolderLocation', NULL, 'Text'ServerName is your name for the serverFolderLocation refers to the folder on the server where your text files are located, e.g. D:\Mssql\LinkedServer3) Use the following syntax to access your text file:SELECT * FROM TestServer...MyExample#txt (note the &lt;b&gt;three&lt;/b&gt; dots, and the hash symbol - a period would interfere with SQL Server syntax)If you use the shorter version of the Schema.ini file, your column names are those contained in the first row of the text file, e.g. MyCol1.If you use the longer version of the Schema.ini file, your column names are those contained in the schema.ini file, e.g. NamedCol1Notes------ You can SELECT and JOIN and INSERT INTO your text files. You cannot use the DELETE or UPDATE commands.- If you do SELECT *, your columns will appear in alphabetic sequence!!!- If you need to give users access to your linked server, you &lt;b&gt;may&lt;/b&gt; have to grant your users read/write access to the Temp folder on SQL Server. This is because one source I read stated that SQL Server needs to create its own temporary files in the Temp folder. I know that I had some problems in enabling users to read files using this approach; but we were also experiencing many problems with the database server, and eventually dumped that machine and used a different one (actually a virtual machine), so my problems may have been caused by something else.</description><pubDate>Thu, 01 Mar 2007 15:08:00 GMT</pubDate><dc:creator>Paul Thornett</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;It is just 17000 records of just one field CustomerID.&lt;/P&gt;&lt;P&gt;I am using everything that people mentioned above for different projects: Linked server with the text driver, OPENROWSET, CLR in 2005 to deal with text files, BCP, an independent (from the third-party) Reporting Database. I also support MS ACCESS /EXCELL VBA import from text files, VBscript from the ASP pages, VBscript by the cscript, whatever. My preferences are to use the back-end processing on the same server after getting the source data into temp tables. It is usually faster then doing the front-end processing or distributed queries.&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 10:05:00 GMT</pubDate><dc:creator>Yelena Varshal</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Howdy All,I agree that authoring a single select per CustomerID in the key file is wasteful and there is no need for the vbs script in this case.  This also sounded like a one-off sort of request, so I thought I would offer a method that did not use a linked server.Run the following query, either through the command line as in the article or in Query Analyzer and set your output options to create the desired output file.&lt;pre style="font: 12px monospace"&gt;&lt;span style="color:blue"&gt;SET NOCOUNT ON&lt;/span&gt;&lt;span style="color:blue"&gt;SELECT&lt;/span&gt;    C.CustomerID,    C.CompanyName,    C.City,    O.OrderDate,    O.Freight&lt;span style="color:blue"&gt;FROM&lt;/span&gt;    dbo.Customers &lt;span style="color:blue"&gt;AS&lt;/span&gt; C    &lt;span style="color:blue"&gt;INNER JOIN&lt;/span&gt; dbo.Orders &lt;span style="color:blue"&gt;AS&lt;/span&gt; O &lt;span style="color:blue"&gt;ON&lt;/span&gt; C.CustomerID = O.CustomerID    &lt;span style="color:blue"&gt;INNER JOIN OPENDATASOURCE&lt;/span&gt;(        &lt;span style="color:red"&gt;'Microsoft.Jet.OLEDB.4.0'&lt;/span&gt;,        &lt;span style="color:red"&gt;'Data Source=c:\;Extended Properties=&amp;quot;text;HDR=No;FMT=Delimited&amp;quot;'&lt;/span&gt;    )...custID#txt &lt;span style="color:blue"&gt;AS&lt;/span&gt; T &lt;span style="color:blue"&gt;ON&lt;/span&gt; T.F1 = C.CustomerID&lt;/pre&gt;Some things of note; • The Data Source is the directory where the file being read is • If there are no Header Rows (HDR=No) the column names are F1, F2, F3 and so on.Cheers</description><pubDate>Thu, 01 Mar 2007 09:04:00 GMT</pubDate><dc:creator>Dennis D. Allen</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;At my company we run into "requests" like this all the time.  Us lowly developers don't have the right to create jack in the production database but the data results the business unit wants come from there.  Our normal solution is to use Excel.  In a Query analyzer window we'll do a create table statement to create a temporary table to hold the data, in this case "create table #tmp (cust varchar(5))"&lt;/P&gt;&lt;P&gt;We'll have a list of clients sent to us in Excel or a text file.  Opening the attachment in Excel.  We'll insert a blank column in front of the data column and define a formula as ="insert into #tmp values('" &amp;amp; A2 &amp;amp; "')"  Copy the formula in A1 to the entire A column.  Copy the column and do a Past...Special...Values.  Copy the column of insert statements into QA and run.  Now you have a temp table in a QA session you can join to the data in the database and use in whatever ways one needs.&lt;/P&gt;&lt;P&gt;We deal with payroll data for millions of people employed throughout the country and it is not uncommon to get a request to pull demographic info on 10-20K people at a time for some report or another.  This method makes these requests trivial to handle.&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 09:01:00 GMT</pubDate><dc:creator>finaltable</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>R L, give us some guidelines or short examples for the benefit of people that are not familiar with perl and sqsh. Hopefully something that makes solution quick and easy.</description><pubDate>Thu, 01 Mar 2007 08:28:00 GMT</pubDate><dc:creator>Predrag Miletic</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>I, too, am tickled by this great discussion.  I appreciate the author who wrote such a clear original article and then seeing the different ways other people would solve this.Personally, I would use the Jet/Access method myself.  However, if there were a reason I couldn't use Access, I would create the set of queries in Excel.  Then the question is how to run them.  I like the Author's suggestion of OSQL.  I also like the DOS suggestion posted earlier.  Both of these are areas I will research more.  Thanks!</description><pubDate>Thu, 01 Mar 2007 08:26:00 GMT</pubDate><dc:creator>JJ B</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Cannot be used in the situation we are discussing at present. This T-SQL would generate statements for every single customer that made an order, but what we need is something to handle a large subset of a large customer base provided in the form of text file.&lt;/P&gt;&lt;P&gt;In other circumstances T-SQL would do just great. I use it often especially for admin tasks.&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 08:25:00 GMT</pubDate><dc:creator>Predrag Miletic</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Since folks are casting around for the "more than one way to do it" - my tendency would be to use perl and sqsh.   Has the advantage of working equally well from a Unix or Windows client, and works whether the database is MS SQL Server, Sybase, or both.&lt;/P&gt;&lt;P&gt;Which simply reflects my own background and circumstances as does the original authors.&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 08:15:00 GMT</pubDate><dc:creator>Roger L Reid</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Hello Paul,Yes, please post more details on using the Jet 4.0 text driver for this type of query. Others have also mentioned Reporting Services and also trying to determine if there is a query that can be done straight from the database by talking to the users and finding out their logic for selecting records in the first place.Thanks,webrunnerP.S. I think this discussion is great. Depending on the situation, you never know which method will be available, so it is good to know as many as possible.</description><pubDate>Thu, 01 Mar 2007 07:50:00 GMT</pubDate><dc:creator>webrunner</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>I agree.  vbs and xls are helpful, at times, but yours is the better solution.</description><pubDate>Thu, 01 Mar 2007 07:44:00 GMT</pubDate><dc:creator>jancorley</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Since we're allowed to use QA and presumably access other DBs on the server, why not BCP in into a DB the list of customers, then use osql to run a single query, joining to the tables in the vendor's DB?The vbs solution requires 17 000 queries, which, IMHO, is ludicrous.P</description><pubDate>Thu, 01 Mar 2007 07:17:00 GMT</pubDate><dc:creator>schleep</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Why not use T-SQL to generate the queries to be executed?  Then cut and paste the result of this into a text file to be executed using OSQL.&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SELECT DISTINCT'SET NOCOUNT ON SELECT C. CustomerID, C. CompanyName, C.City, O. OrderDate, O. Freight FROM Customers C INNER JOIN Orders  O  ON C.CustomerID = O.CustomerID WHERE C.CustomerID = '''+C.CustomerId+''''FROM Customers C      INNER JOIN     Orders O ON C.CustomerID = O.CustomerID&lt;/FONT&gt;&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 07:12:00 GMT</pubDate><dc:creator>tripleAxe</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Fair enough - it could be a useful solution, I agree.&lt;/P&gt;&lt;P&gt;My personal preference these days is reporting services - it takes 5 minutes to set up a data source, run a query and deploy to the intranet, then dump it to Excel.&lt;/P&gt;&lt;P&gt;Once you've taught your users how to use autofilters you can dump anything you want in half an hour and everyone is happy.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 04:15:00 GMT</pubDate><dc:creator>Richard Gardner-291039</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Absolutely agree Richard. But assumption here is that one would do what you suggest by default and not just jump every time end user says hop (well, unless you are junior DBA ;-)).But once your discussion with requestor is exhausted and you end up with task like this then tech solutions discussed here is exactly what you need. &lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 04:08:00 GMT</pubDate><dc:creator>Predrag Miletic</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;This article gave me a nice insight into vbs since I did not use it for a long time, but agree with you guys that is a bit of overkill. I would use Excel myself, but have to admit that the other 3 suggestions are very nice (Dave's querysql, Paul's Jet and Daniel's DOS).&lt;/P&gt;&lt;P&gt;Another solution would be MS Access (even though personally it is my last resort): import text file, link the other tables from SQL and create report.&lt;/P&gt;&lt;P&gt;Paul, could you please provide us with more details on your Jet 4.0 text driver solution.&lt;/P&gt;&lt;P&gt;Rgds&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 03:55:00 GMT</pubDate><dc:creator>Predrag Miletic</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Interesting tecchy answers......&lt;/P&gt;&lt;P&gt;To my mind the problem would be better solved by asking the user what their criteria is for choosing the 17,000 customers in the first place, there must have been some reason and therefore logic behind the distinction, then write that query instead and you've saved the user the bother of ever doing the same thing again.... &lt;/P&gt;&lt;P&gt;If I spent my life doing what users told me instead of what they need to be done I'd be an Excel expert..........&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 03:55:00 GMT</pubDate><dc:creator>Richard Gardner-291039</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>Hi there,this topic brings me actually to another issue. Considering the original limitations of query and report only, would it have been acceptable to write a stored procedure? That is obviously if the server is 2005 and has CLR enabled.I had some similar topics not too long ago to implement data pushing usijng C# stored procedures rather than using polling mechanisms to update client workstations.Using a stored procedure to output to a text file would allow you to communicate with outside processes as well as build a bridge for older or incompatible systems.As I am new, please allow me the question: have there been any topics on CLR stored procedures?Stefan</description><pubDate>Thu, 01 Mar 2007 01:47:00 GMT</pubDate><dc:creator>Stefan Morrow</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I like the approach to solving the problem, but the VBscript seems like overkill. I've also used excel several times to solve these problems. But when they are this easy why not use good old DOS:&lt;/P&gt;&lt;P&gt;FOR /F %i in (custID.txt) do @echo set nocount on select %i &amp;gt;&amp;gt; custID.qry&lt;/P&gt;&lt;P&gt;This solved your problem in just one line of code. For more information on the FOR command, just type "help for" on the command line.&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 01:26:00 GMT</pubDate><dc:creator>Daniel van der Meulen</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>I prefer to use a linked server using the Jet 4.0 text driver. This technique allows me to treat the incoming text file as a table, so I can join to it in the normal way. If anyone is interested, I can provide more detail on this. It's a technique I use a lot when dealing with tab-delimited files which are used either for input or output (yes, I can also INSERT new rows into my text files).</description><pubDate>Thu, 01 Mar 2007 01:20:00 GMT</pubDate><dc:creator>Paul Thornett</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;whereas my solution was to write an application in C++ which lets me use a placeholder in a sql file, and specify a tab delimited text file to provide the values.&lt;/P&gt;&lt;P&gt;-- test.sql&lt;/P&gt;&lt;PRE&gt;SELECT TestTable.RowID, TestTable.RowName FROM TestTable WHERE TestTable.RowID = '@1'&lt;/PRE&gt;&lt;P&gt;-- input.txt&lt;/P&gt;&lt;PRE&gt;123321456654&lt;/PRE&gt;&lt;P&gt;-- console&lt;/P&gt;&lt;PRE&gt;querysql.exe -server=(local) -database=testdb -sql=test.sql -input=input.txt -output=output.txt&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;very handy because I don't have to create any tempoary files with all the sql statements.  Output can be either to screen or to a file.  Works with either a ODBC-DSN or direct to the SQL server.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Would this be of interest to anybody else?&lt;/P&gt;</description><pubDate>Thu, 01 Mar 2007 01:06:00 GMT</pubDate><dc:creator>Dave Dustin</dc:creator></item><item><title>RE: Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Nice solution. As a DBA I faced similar tasks many times. My usual way of completing them is by using Excel:&lt;/P&gt;&lt;P&gt;1. Start with 1 column&lt;/P&gt;&lt;P&gt;ALFKIANTONAROUTBERGSBOLIDBONAPBSBEVCACTUCONSHDOGGYFOLIGFOLKOFRANKFRANRFRANSFURIB&lt;/P&gt;&lt;P&gt;2. Insert a column in front of it&lt;/P&gt;&lt;P&gt;3. Type&lt;/P&gt;&lt;P&gt;Placeholder1&lt;/P&gt;&lt;P&gt;in the first cell of this column. Drag and drop the value to populate the whole column.&lt;/P&gt;&lt;P&gt;4. Type&lt;/P&gt;&lt;P&gt;Placeholder2&lt;/P&gt;&lt;P&gt;in the first cell of the 3rd column.  Drag and drop the value to populate the whole column.&lt;/P&gt;&lt;P&gt;5. "Save As" to a text file&lt;/P&gt;&lt;P&gt;6. Open the saved text part in notepad. do Edit/Replace replacing&lt;/P&gt;&lt;P&gt;Placeholder1 with&lt;/P&gt;&lt;P&gt;SET NOCOUNT ON SELECT C. CustomerID, C. CompanyName, C.City, O. OrderDate, O. Freight FROM Customers C INNER JOIN Orders  O    " ON C.CustomerID = O.CustomerID WHERE C.CustomerID = '&lt;/P&gt;&lt;P&gt;then replacing Placeholder2 with a single quote. Make sure all TABs and Commas are replaced with empty strings as well.&lt;/P&gt;&lt;P&gt;Save the output.&lt;/P&gt;&lt;P&gt;It is more simple than it sounds!&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anatol Romanov&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Wed, 28 Feb 2007 22:12:00 GMT</pubDate><dc:creator>Anatol Romanov-404520</dc:creator></item><item><title>Running a Query Using a Text File for Input</title><link>http://www.sqlservercentral.com/Forums/Topic335844-219-1.aspx</link><description>&lt;P&gt;Comments posted here are about the content posted at &lt;A href="http://www.sqlservercentral.com/columnists/rcarlson/2801.asp"&gt;http://www.sqlservercentral.com/columnists/rcarlson/2801.asp&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The original solution required much more than this article suggested. The response from everyone emphasized the need to always examine the alternatives.  Sometimes the easiest solution is not the best and vice versa.  I am very happy that this article generated an active response.  The comment about what users want and what they need is an important one to remember.&lt;/P&gt;&lt;P&gt;Thanks for the great discussion.&lt;/P&gt;</description><pubDate>Wed, 10 Jan 2007 09:26:00 GMT</pubDate><dc:creator>rscarlson</dc:creator></item></channel></rss>