Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Date comparison record selection formula Post Reply Post New Topic
Author Message
sumthinsup33
Newbie
Newbie


Joined: 10 Feb 2010
Location: United States
Online Status: Offline
Posts: 2
Quote sumthinsup33 Replybullet Topic: Date comparison record selection formula
     Posted: 10 Feb 2010 at 2:04am

I am new to Crystal Reports and need to create a record selection formula which compares two different database date fields in a M/D/YYYY HH:MM:SS date format. A record would be returned when {table1.date} >= {table2.date}. Can anyone make any suggestions on how to I can go about this?

An alternative that's been considered is to return a record when the time of the date stamp in {table1.date} is greater than or equal to 08:00 PM. Is this possible?

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Feb 2010 at 7:35am
If you have your tables joined correctly then in your select statement just add your condition as you have it in your post:
{table1.date}>={table2.date}
IP IP Logged
sumthinsup33
Newbie
Newbie


Joined: 10 Feb 2010
Location: United States
Online Status: Offline
Posts: 2
Quote sumthinsup33 Replybullet Posted: 11 Feb 2010 at 5:00am

Thanks. Revisiting the joins helped improve the results but I'm still missing something. After my post, I tested the formula a different way and confirmed that it is correct. There are additional formulas in the selection criteria and the report looked okay until I added the date formula, so I assumed it was the issue but now I know the problem lies elsewhere. Let me explain more fully my requirement to see if you can provide some further insights.

 

I want to display a record in every instance one of two conditions is met:

 

1) A new order was entered in the past seven days, {table1.orderdate}, for a particular product, {products.code} = "IUD", or

 

2) An order change for a particular product, {products.code} = "IUD", has occurred after the order process date, {table1.processdate}, and during the past seven days

 

Order change records are written to log tables, which contain a transaction date stamps (date & time). There are several of these log tables, one of which is table2. As an example, I am using the transaction date stamp of table2, {table2.changedate}, to limit the report to changes occurring in the past seven days but after the original process date and time, { table1.processdate}.

 

I need to display the record each time either criterion is met. For example, if a new order was created three days ago but it was changed the next day, the record would appear on the report twice, once in connection with the new order and the second time to show the subsequent update to the order.

 

Based on these requirements, I’ve written the selection formula below using different variations but none of them work properly. Writing it one way, too many change records from table2 are displayed; changing it other ways displays only the new orders or just those records that have updates. Could you review the syntax below and tell me where I may be going wrong with my logic and how to capture all of the desired records?

 

currentdate < dateadd('d',7,{table1.orderdate}) and

{products.code} = " IUD" or

currentdate < dateadd('d',7,{ table2.changedate }) and

{table2.changedate} >={ table1.processdate} and

{products.code} = "IUD"

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Feb 2010 at 7:28pm
Part of the answer depends on if the log table has all matching records from table1 or if you had to do an outer join. Your selectg statement can turn an outerjoin into an innerjoin and drop records.
How ia this data set up?
Also you need to parenth your statements to handle ANDs and ORs in the correct way. Something like:
 
{products.code} = "IUD" and
(currentdate < dateadd('d',7,{table1.orderdate} or
(currentdate < dateadd('d',7,{ table2.changedate } and {table2.changedate} >={ table1.processdate}))

 

IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum