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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include a record based on two records 2

Status
Not open for further replies.

cisscott

IS-IT--Management
Apr 21, 2003
115
US
Crystal Reports 9.1
SQL Server 2000 8.00.760 on W2K Adv Server

We have recently begun selling product over the internet. Some people chooose to have their purchase mailed to them, others come and pick it up. In the live.audit.dbo table there is a transaction type "H" for held, "R" for Reserved/Paid, and "X" for Cancelled. I designed a report that we run each morning that prints out each order that is status "R" and live.deliverymethod = 'MAIL'. However I have to also print out the 'X' type codes to be sure we don't mail to customers who purchased and then cancelled. So here's an example data set for orderid 851:

Orderid Type Charges datetime
851 H 0.00 2005-09-22 8:00:00am
851 R 21.95 2005-09-22 8:01:17am
851 X (21.95) 2005-09-22 8:32:46am

The question is How can I NOT include orderID 851 on the products to mail list based on the fact that one record is type R and a seperate record for the same order is type X?
 
I had seen similar situation in my database. This is what I did. It worked for me.
Connect the table to itself by Orderid (add the same table twice and rename them, say Table-R and Table-X). When you choosing the records, choose the ones with type "R" in Table-R but NOT type "X" in Table-X.
 
You could group on OrderID and then create a formula:

if {table.type} = "X" then 1

Then go to report->selection formula->GROUP and enter:

Sum({table.type},{table.OrderID}) = 0

If you could have a situation where a customer changes his/her mind and "uncancels", so that you need to test for the most recent transaction, then change the group selection formula to:

{table.date} = maximum({table.date},{table.orderID}) and
{table.type} <> "X"

-LB
 
Excellent suggestions, thanks to both of you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top