This is a discussion on Query paramaters within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> I am looking for a way to read a seperate .txt file and extract the paramaters for a query. ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I am looking for a way to read a seperate .txt file and extract the paramaters for a query. I am given a .txt file with several thousand numbers a day, to query against the database. I would very much like to call the file and read it's contents in as the paramater. Is this possible through using just sql? for example, current method (paraphrased extensively) select * from emp where emp_number in (1, 2, 3, 4, 5, 6 etc...); desired method select * from emp where emp_number in (call txt_file_with_numbers.txt); |
| |||
| Perhaps you can create a C or C++ program that creates your SELECT stmt at run time by reading in these values from a text file. Something along these lines... char szSqlString[1000]; char szNumbersList[1000]; // Create a function that reads in the list of numbers from a text file and writes them to 'szNumbersList'... GetListOfNumbersFromTextFile(szTextFileName, szNumbersList); snprintf(szSqlString, 1000, "SELECT * from emp where emp_number in ( %s )", szNumbersList); SQLExecDirect(hstmt, szSqlString, SQL_NTS); Alternatively, you could try to do this with parameters, but this would be MUCH more work. |
| ||||
| By golley, that works... Thanks. "Warren Read" wrote: > Perhaps you can create a C or C++ program that creates your SELECT stmt at > run time by reading in these values from a text file. > > Something along these lines... > > > char szSqlString[1000]; > char szNumbersList[1000]; > > // Create a function that reads in the list of numbers from a text file and > writes them to 'szNumbersList'... > GetListOfNumbersFromTextFile(szTextFileName, szNumbersList); > > snprintf(szSqlString, 1000, "SELECT * from emp where emp_number in ( %s )", > szNumbersList); > SQLExecDirect(hstmt, szSqlString, SQL_NTS); > > > Alternatively, you could try to do this with parameters, but this would be > MUCH more work. > > > > > |
| Thread Tools | |
| Display Modes | |
|
|