A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Finding Non-Repeated Records in a Query



 
 
Thread Tools Display Modes
  #1  
Old July 22nd, 2004, 05:34 PM
Chris Guimbellot
external usenet poster
 
Posts: n/a
Default Finding Non-Repeated Records in a Query

Hello,

Access2K.

I have a table or orders that records data in a way that when an order is
placed, then cancelled, the data looks as follows (the important rows are 1
and 3. notice the transaction column):

ID Transaction Item QTY Price OrderStatus
1 1000 123 1 10.00 New
2 1001 124 5 100.00 New
3 1000 123 -1 -10.00 Cancel

Is there any way when I query this table, I can retrieve only the rows that
do not have cancelled transactions? Something like querying to say if the
transaction number appears more than once, throw out all of the records with
that transaction number.

Sorry that I may not be asking this question correctly, but is this
possible? Thanks,

Chris



  #2  
Old July 22nd, 2004, 05:54 PM
xxplusxx
external usenet poster
 
Posts: n/a
Default Finding Non-Repeated Records in a Query


i guess you should base your query or consider also
transaction status.
the reason for these is what if you have the same item
number but an addition new transaction???

select * from table where status"cancel"

-----Original Message-----
Hello,

Access2K.

I have a table or orders that records data in a way that

when an order is
placed, then cancelled, the data looks as follows (the

important rows are 1
and 3. notice the transaction column):

ID Transaction Item QTY Price OrderStatus
1 1000 123 1 10.00 New
2 1001 124 5 100.00 New
3 1000 123 -1 -10.00

Cancel

Is there any way when I query this table, I can retrieve

only the rows that
do not have cancelled transactions? Something like

querying to say if the
transaction number appears more than once, throw out all

of the records with
that transaction number.

Sorry that I may not be asking this question correctly,

but is this
possible? Thanks,

Chris



.

  #3  
Old July 22nd, 2004, 06:55 PM
John Vinson
external usenet poster
 
Posts: n/a
Default Finding Non-Repeated Records in a Query

On Thu, 22 Jul 2004 12:34:19 -0400, "Chris Guimbellot"
wrote:

Hello,

Access2K.

I have a table or orders that records data in a way that when an order is
placed, then cancelled, the data looks as follows (the important rows are 1
and 3. notice the transaction column):

ID Transaction Item QTY Price OrderStatus
1 1000 123 1 10.00 New
2 1001 124 5 100.00 New
3 1000 123 -1 -10.00 Cancel

Is there any way when I query this table, I can retrieve only the rows that
do not have cancelled transactions? Something like querying to say if the
transaction number appears more than once, throw out all of the records with
that transaction number.


You can use a NOT EXISTS clause in the query:

SELECT yourtable.*
FROM yourtable
WHERE NOT EXISTS
(SELECT Transaction FROM yourtable AS X
WHERE X.Transaction=yourtable.Transaction
AND X.OrderStatus = "Cancel")

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
  #4  
Old July 22nd, 2004, 08:40 PM
Chris Guimbellot
external usenet poster
 
Posts: n/a
Default Finding Non-Repeated Records in a Query

John,

That worked like a champ. Thanks a lot.

Chris

"John Vinson" wrote in message
...
On Thu, 22 Jul 2004 12:34:19 -0400, "Chris Guimbellot"
wrote:

Hello,

Access2K.

I have a table or orders that records data in a way that when an order is
placed, then cancelled, the data looks as follows (the important rows are

1
and 3. notice the transaction column):

ID Transaction Item QTY Price OrderStatus
1 1000 123 1 10.00 New
2 1001 124 5 100.00 New
3 1000 123 -1 -10.00 Cancel

Is there any way when I query this table, I can retrieve only the rows

that
do not have cancelled transactions? Something like querying to say if the
transaction number appears more than once, throw out all of the records

with
that transaction number.


You can use a NOT EXISTS clause in the query:

SELECT yourtable.*
FROM yourtable
WHERE NOT EXISTS
(SELECT Transaction FROM yourtable AS X
WHERE X.Transaction=yourtable.Transaction
AND X.OrderStatus = "Cancel")

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public



  #5  
Old July 22nd, 2004, 09:26 PM
Chris Guimbellot
external usenet poster
 
Posts: n/a
Default Finding Non-Repeated Records in a Query

John,

Is there any way to modify that code so cancelled orders whose original
order is not in the recordset are still included. The reason is because
orders may be placed during one period of time and cancelled during another.
I run monthly invoices and an order placed this month must be invoiced. Next
month, though, it may be cancelled, and the invoice for that month needs to
show the cancellation so the cash can be credited. Any ideas? Thanks,

Chris

"John Vinson" wrote in message
...
On Thu, 22 Jul 2004 12:34:19 -0400, "Chris Guimbellot"
wrote:

Hello,

Access2K.

I have a table or orders that records data in a way that when an order is
placed, then cancelled, the data looks as follows (the important rows are

1
and 3. notice the transaction column):

ID Transaction Item QTY Price OrderStatus
1 1000 123 1 10.00 New
2 1001 124 5 100.00 New
3 1000 123 -1 -10.00 Cancel

Is there any way when I query this table, I can retrieve only the rows

that
do not have cancelled transactions? Something like querying to say if the
transaction number appears more than once, throw out all of the records

with
that transaction number.


You can use a NOT EXISTS clause in the query:

SELECT yourtable.*
FROM yourtable
WHERE NOT EXISTS
(SELECT Transaction FROM yourtable AS X
WHERE X.Transaction=yourtable.Transaction
AND X.OrderStatus = "Cancel")

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public



  #6  
Old July 24th, 2004, 01:01 AM
John Vinson
external usenet poster
 
Posts: n/a
Default Finding Non-Repeated Records in a Query

On Thu, 22 Jul 2004 16:26:57 -0400, "Chris Guimbellot"
wrote:

Is there any way to modify that code so cancelled orders whose original
order is not in the recordset are still included.


Sure - just include additional criteria in the subquery to select only
those records that you want to exclude.

John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
 




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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying all the duplicate records in a duplicate query Paul James Running & Setting Up Queries 6 July 15th, 2004 09:28 AM
append Query duplicating records Alex Running & Setting Up Queries 1 July 8th, 2004 01:31 PM
Query combining multiple records from one table can't add records Clint Marshall Running & Setting Up Queries 4 July 8th, 2004 01:25 PM
can't append records in append query Greg Clements Running & Setting Up Queries 1 July 2nd, 2004 04:29 PM
Finding and deleting repeated records in WORD Document. Richard General Discussion 1 May 23rd, 2004 02:01 AM


All times are GMT +1. The time now is 09:45 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.