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

crSunday

Status
Not open for further replies.

DanHD

Technical User
Dec 1, 2008
98
NL
hello

i wan't to create a formula like this:

if ({order.date}) = CRSunday then 'overtime'

So, if the order is placed on a sunday, then the text 'overtime' must be printed. I've try a lot of variaties, without any results.
 
If you're using CR XI, then there is a function called DayOfWeek() that will calculate this for you. The information for it can be found in the CR help file, but this code should do the trick:

if DayOfWeek({order.date}) = 1 then 'overtime'

The DayOfWeek() function returns whole numbers, and 1 represents Sunday. You also have the option of specifying a different day as the beginning of the week., for instance:

if DayOfWeek({order.date}, crMonday) = 7 then 'overtime'

is the same as the first formula. crMonday and the like is a constant for date functions.
 
thanks
your explanation helped me further then the help file.
 
hi I worked it out and.......... maybe you can help me one more time

this first option works correctly:

if DayOfWeek ({MPProjektBuchungserfassung.LeistungsTag})= 7 then 'saturday' else
if DayOfWeek ({MPProjektBuchungserfassung.LeistungsTag})= 1 then 'saunday'

But when I want to do this in a case, I receive an error on
directly on the first case, CR expected a date or time

select{MPProjektBuchungserfassung.LeistungsTag}
case DayOfWeek ({MPProjektBuchungserfassung.LeistungsTag})= 7:
"saturday"
case DayOfWeek ({MPProjektBuchungserfassung.LeistungsTag})= 1:
"sunday"
Default:
"C";
 
Not sure but I think you need the following

select dayofweek({MPProjektBuchungserfassung.LeistungsTag})
case 7:
"saturday"
case 1:
"sunday"
Default:
"C";
 
Thanks!!
It works again!
Have a nice weekend.
 
oke, that was to early
By default, I wan't to have a formula, this results in an error, a string is expected. Is this not possible?

select dayofweek({MPProjektBuchungserfassung.LeistungsTag})
case 7:
"saturday"
case 1:
"sunday"
Default:
if Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily") > 8
then Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily")-8;



Only a databasefield also results in an error

select dayofweek({MPProjektBuchungserfassung.LeistungsTag})
case 7:
"saturday"
case 1:
"sunday"
Default:
{MPProjektBuchungserfassung.Menge};
 
Hi DanHD,

You'll have to convert to string the number you want to have for the Default option:

select dayofweek({MPProjektBuchungserfassung.LeistungsTag})
case 7:
"saturday"
case 1:
"sunday"
Default:
if Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily") > 8
then totext(Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily")-8);


Dana T.
 
OK I understand that.
But I have other formulas that are based on this field.
Here I receive errors because the totext. They also expected then a string.
Example the field {@>=3} is based on the field mean above {@<8}, so because the totext, the content of {@>=3} gives then a problemm:

if {@>8} >= 3
then 3
else {@>8}

and on field {@>=3} are also other formulas build.
 
What other formulas? A select/case formula is just a fancy if/then formula, and like an if/then, all potential formula results must be of the same datatype--all strings (using totext() if necessary), all dates, or all numbers. In your last example, all results must be numbers, so there would be no need for totext().

-LB
 
okay so if I understand correctly, is a case not suitable for a combination of text (saturday) and a default formula.
 
I am resolved in the following way,
Thank you all for your valuable input.

if DayOfWeek ({MPProjektBuchungserfassung.LeistungsTag})= 7 then 0 else
if DayOfWeek ({MPProjektBuchungserfassung.LeistungsTag})= 1 then 0 else
if Sum ({@overwerk_tot}, {@weeknr}) > 40 then
if Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily") > 8 then
Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily") - 8
 
Or to shorten it, you could go:

if DayOfWeek({MPProjektBuchungserfassung.LeistungsTag})in [1,7]
then 0
else
if sum({@overwerk_tot}, {@weeknr}) > 40 and Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily") > 8 then
Sum ({@overwerk_tot}, {MPProjektBuchungserfassung.LeistungsTag}, "daily") - 8

It should be less processing time in the report, but either way you should be fine.
 
Select/case is fine for any datatype, as long as the default is of the same datatype as the other possible results--the same as is true for an if/then formula.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top