Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Querying a query 1

Status
Not open for further replies.

Guggly

Programmer
Jan 18, 2004
110
US
I'm not sure if I'm explaining this question correctly, but basically I'm working on a database project in VB .Net and using a Microsoft Access backend for the database (might eventually upgrade it to SQL Server, not sure).

How can I query the contents of a query (which is returned in form of a recordset) with an SQL statement? In other words, I don't want to have to write the query to the database either as a query or as a table, I just want to be able to use the values that were returned, in a recordset, and perform some further calculations on them via an SQL statement.

Is this possible? If not, what are my options?

Thanks! -- Mike
 
not sure if this is what you're after but have a look at the Datatable.Select command.
This allows you to run a query on a table and returns an array of rows.
One of the best features of ADO.Net
 
Thanks Jubble! Can I actually run an SQL statement there? In the examples I've seen, it only uses Select with criteria as the filter. Can I put some kind of an IN SELECT subquery here and filter on that?

Also, what if I want to join my recordset with another table or query in order to get the data I need? That's something that couldn't be done with a filter, how can I go about that?
 
You can run a full SQL statement in the Select method (like you've found out it is used for setting criteria on a particular field).

If you want to join one statement to anohter table, either do that in the original SQL statement or use a DataSet and set up Relations.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Okay, I've finally gotten around to working on this project again, but when I try the above suggestions it throws an error which says "Missing operand before 'In' operator."

Below is my line of code, what am I doing wrong?

Thanks! -- Mike

Code:
objDataSet.Tables("ItemsList").Select("Not In (SELECT tbl_UsedItems.ID FROM tbl_UsedItems WHERE ((tbl_UsedItems.Reusable)=False))")
 
You can run a full SQL statement in the Select method (like you've found out it is used for setting criteria on a particular field).
This is my fault due to a typo as it should have been "You can't run a full SQL statement..."

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Don't you need to specify the Field name that contains the value to check against the IN also? ie:

Code:
ID Not In (SELECT tbl_UsedItems.ID FROM tbl_UsedItems WHERE ((tbl_UsedItems.Reusable)=False))

And like Ca8msm said, I don't think you can run another select statment inside a select, unless perhaps if you are selecting against the data in the datatable...

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Thanks, no wonder it didn't work :). Rick, you're absolutely right, I didn't put in a field name to compare the list agaist.

So, where do I go from here? ca8msm, you suggested using Relations, but from what I can tell a Relation is what is in Access as a Relationship and MSSQL as a Database Diagram. If so, then I don't see how I could use that to filter out my list. Or am I missing something?

I could selectively create my dataset as it's being built by checking it against the table I need to compare with, but since SQL seems much faster for this type of thing I've been trying to do it via SQL. Is that even possible?

Thanks! -- Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top