Unix Technical Forum

Query paramaters

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. ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > MS SQL ODBC

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 09:46 PM
=?Utf-8?B?QWxleA==?=
 
Posts: n/a
Default 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 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);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 09:46 PM
Warren Read
 
Posts: n/a
Default RE: Query paramaters

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.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 09:46 PM
=?Utf-8?B?QWxleA==?=
 
Posts: n/a
Default RE: Query paramaters

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.
>
>
>
>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:17 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com