Tuesday, March 20, 2012

Query paramaters

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 number
s
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(szTextFileN
ame, 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 an
d
> writes them to 'szNumbersList'...
> GetListOfNumbersFromTextFile(szTextFileN
ame, 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.
>
>
>

No comments:

Post a Comment