Home > Archive > MS SQL Server ODBC > June 2005 > Query paramaters









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Query paramaters
Alex

2005-06-16, 8:23 pm

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_number
s.txt);
Warren Read

2005-06-21, 8:23 pm

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'...
GetListOfNumbersFrom
TextFile(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.




Alex

2005-06-21, 8:23 pm

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'...
> GetListOfNumbersFrom
TextFile(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.
>
>
>
>
>

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com