Print Page | Close Window

Formula giving Incorrect Results

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22277
Printed Date: 28 Apr 2024 at 4:33am


Topic: Formula giving Incorrect Results
Posted By: Bassman75
Subject: Formula giving Incorrect Results
Date Posted: 29 Mar 2017 at 7:03am
I'm using Crystal 2011 and have what I thought was a pretty cut and dry formula, however if I use a date range in 2017, the results are correct. When I use any dates in 2016, I get the result of the "else" in the statement for all records, when I should be getting ".84" for a majority since the Date Parameter is less than the hard coded date.

Scan Date Formula:

Local Datetimevar scanDATE:={posj_event.business_date};
Local Stringvar scanDateSTR:=ToText(scanDATE,"MMddyy");
scanDateSTR

Formula that does not work when 2016 date is entered:

Local NumberVar rateNUM:=If upcSTR="3943000050" and {@Scan Date} < "030617"
then rateNUM:=.84 else rateNUM:=.01;
rateNUM



Replies:
Posted By: kevlray
Date Posted: 29 Mar 2017 at 10:57am
Have you double checked the value of scanDateSTR to see if you are getting the value you are expecting? You also do not show where the value for upcSTR comes from.  We can only assume that is correct also.


Posted By: DBlank
Date Posted: 29 Mar 2017 at 10:59am
Also, I would really not use a < comparison on a string like that. Use the date data types, not strings.
A quick test in crystal returns a false on
"120616" < "030617".


Posted By: Bassman75
Date Posted: 30 Mar 2017 at 2:11am
I am getting the value I am expecting,

120216
120316
120416
120516



Posted By: Bassman75
Date Posted: 30 Mar 2017 at 2:13am
DBlank, I will give that a try. So what you are saying is use the actual value of the date, which is originally a date data type, rather than convert it to a string?


Posted By: DBlank
Date Posted: 30 Mar 2017 at 2:35am
correct


Posted By: Bassman75
Date Posted: 30 Mar 2017 at 2:41am
Got it, works like a charm. Interesting that converting to a string behaves that way. Thank you for the help!!


Posted By: DBlank
Date Posted: 30 Mar 2017 at 2:46am
"120616" < "030617"
it isn't numeric
the 1 is > the 0
I think, if you had to use as string you want to use
yyyyMMdd format but I still think using the actual date field is way more reliable.



Print Page | Close Window