Complex SQL statement 
Author Message
 Complex SQL statement

Hi all, sorry for multiposting.

I need to create a recordset based on a table to use it to insert a new
record in a different table with a different scope and make sure the user
never creates copies of a certain record.

Table 1 contains data related to invoices and has a numeric field that
stores invoice numbers which are unique.

The user selects a specific invoice number and adds a new record in Table 2.

When the user inserts a new record into Table 2, I want him/her to only see
invoice numbers that have NOT already been inserted into Table 2.

At the moment, before opening the form thru which this operation is
accomplished, I do a comparison of each record in Table 2 with the ones in
Table 1 and remove, from the recordset based on Table 1, all records that
already appear in table 2. On a PIII 650 this is preatty fast with only a
few hundreds invoices stored. But as the database grows, I'm afraid this can
turn into a rather time consuming task.

So, my question is:
Is there an SQL statement (or any better way to do this) that can create a
recordset based on Table 1 but that does NOT include all records that were
already added to Table 2, based an a unique number field?

Obviosly this would be a lot easier if there was a flag field in Table 1 to
just store a boolean value showing that a particular record has already been
used, but unfortunately it's too late now and the database cannot be
modified.

I thank you for reading this, I hope it's clear.

--
Andy,



Sat, 12 Nov 2005 01:56:35 GMT  
 Complex SQL statement
Without testing, I suggest
    SELECT col, col FROM Table1 WHERE Table1.id NOT IN (SELECT ID FROM
Table2)
hth
--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________


Quote:
> Hi all, sorry for multiposting.

> I need to create a recordset based on a table to use it to insert a new
> record in a different table with a different scope and make sure the user
> never creates copies of a certain record.

> Table 1 contains data related to invoices and has a numeric field that
> stores invoice numbers which are unique.

> The user selects a specific invoice number and adds a new record in Table
2.

> When the user inserts a new record into Table 2, I want him/her to only
see
> invoice numbers that have NOT already been inserted into Table 2.

> At the moment, before opening the form thru which this operation is
> accomplished, I do a comparison of each record in Table 2 with the ones in
> Table 1 and remove, from the recordset based on Table 1, all records that
> already appear in table 2. On a PIII 650 this is preatty fast with only a
> few hundreds invoices stored. But as the database grows, I'm afraid this
can
> turn into a rather time consuming task.

> So, my question is:
> Is there an SQL statement (or any better way to do this) that can create a
> recordset based on Table 1 but that does NOT include all records that were
> already added to Table 2, based an a unique number field?

> Obviosly this would be a lot easier if there was a flag field in Table 1
to
> just store a boolean value showing that a particular record has already
been
> used, but unfortunately it's too late now and the database cannot be
> modified.

> I thank you for reading this, I hope it's clear.

> --
> Andy,




Sat, 12 Nov 2005 02:18:14 GMT  
 Complex SQL statement
Bill,

thanks a lot, it works great.

Andy.



Quote:
> Without testing, I suggest
>     SELECT col, col FROM Table1 WHERE Table1.id NOT IN (SELECT ID FROM
> Table2)
> hth
> --
> ____________________________________
> Bill Vaughn
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> __________________________________



> > Hi all, sorry for multiposting.

> > I need to create a recordset based on a table to use it to insert a new
> > record in a different table with a different scope and make sure the
user
> > never creates copies of a certain record.

> > Table 1 contains data related to invoices and has a numeric field that
> > stores invoice numbers which are unique.

> > The user selects a specific invoice number and adds a new record in
Table
> 2.

> > When the user inserts a new record into Table 2, I want him/her to only
> see
> > invoice numbers that have NOT already been inserted into Table 2.

> > At the moment, before opening the form thru which this operation is
> > accomplished, I do a comparison of each record in Table 2 with the ones
in
> > Table 1 and remove, from the recordset based on Table 1, all records
that
> > already appear in table 2. On a PIII 650 this is preatty fast with only
a
> > few hundreds invoices stored. But as the database grows, I'm afraid this
> can
> > turn into a rather time consuming task.

> > So, my question is:
> > Is there an SQL statement (or any better way to do this) that can create
a
> > recordset based on Table 1 but that does NOT include all records that
were
> > already added to Table 2, based an a unique number field?

> > Obviosly this would be a lot easier if there was a flag field in Table 1
> to
> > just store a boolean value showing that a particular record has already
> been
> > used, but unfortunately it's too late now and the database cannot be
> > modified.

> > I thank you for reading this, I hope it's clear.

> > --
> > Andy,




Sun, 13 Nov 2005 04:16:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Complex SQL Statement

2. Help with complex SQL statement

3. Help needed - ODBC & complex SQL Statement

4. Saving with Complex SQL statement

5. Long and complex if statement

6. Complex If Statements

7. running sql code record by record instead of statement by statement

8. Complex String Manipulation - Well Complex For Me Anyway

9. SQL's with complex queries

10. SQL Parsing to Complex

11. SQL declaration too complex?

12. complex SQL query

 

 
Powered by phpBB® Forum Software