Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: How to modify a parameter value using a formula Post Reply Post New Topic
Author Message
Appelsap2
Newbie
Newbie


Joined: 17 Apr 2009
Online Status: Offline
Posts: 2
Quote Appelsap2 Replybullet Topic: How to modify a parameter value using a formula
     Posted: 17 Apr 2009 at 12:23am
Hello,
 
i'm fairly new to Crystal reports.. it's possible i'm trying to achieve something in a difficult way while an easier way is also available.. if so, please let me know.
 
The report i'm working on uses a field with a selection. The field is of the type datetime and the parameter that should be used to feed the selection is also datetime, and modifying the data structure or view is not possible. However, entering 2009-01-01 00:00:00 is annoying to users.
 
As far as i know, the parameter should really be of the same type as the data field.
 
I'm trying to create a workaround by creating a second parameter of type "date", and then creating a formula which should work like this:
 
{?OriginalParam} := DateTime ({?NewParam},  TimeValue (00, 00,00 ))
 
The formula is included in the report header so it will be fired.
 
However, this solution does not work. CR says there is an error in the formula.
 
Another approach, using the results of a formula as a starting point of a selection also didn't work because in the selection expert I was not able to select the formula, only parameters were allowed.
 
What should I do? The problem can't be that unique??
 
i'm using CR 11
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Apr 2009 at 6:57am
Use a formula to convert the original field to a date
date({table.datetimefield})
make your parameter a date type
point the parameter to the formula field (instead of the original datetime field) in your select statement.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 Apr 2009 at 7:02am
why not just replace the using of the originalParam with the newParam?
 
If the param is in a filter, they should be interchangeable.  If the param is used in a call to a SQL statement, like a param to a stored proc, then my idea probably won't work. 
 
I don't think that you can change a parameter, because if I remember correctly, the data is retrieved before any formula is executed.  the error could be a type a mismatch.
 
I would try hard coding the time value or just displaying the results of the formula without the assignment, sometimes I find my bonehead mistakes that way.
 
 
IP IP Logged
Appelsap2
Newbie
Newbie


Joined: 17 Apr 2009
Online Status: Offline
Posts: 2
Quote Appelsap2 Replybullet Posted: 17 Apr 2009 at 7:10am
Originally posted by DBlank

Use a formula to convert the original field to a date
date({table.datetimefield})
make your parameter a date type
point the parameter to the formula field (instead of the original datetime field) in your select statement.
I'm stunned that it's that easy, this worked. I was thinking the other way around the whole time and was trying to cast the parameter.

Thanks a million, it's just in time (4:09 PM right now here, and it should be finished today..)
 
:)
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Apr 2009 at 7:10am

Hi Lockwelle,

You would think that it is not possible due to the sequence of the reading of records but I have done it several times for the same reasoning.
You can actually have the parameter = the formula that converts a field from a datetime to a date without any errors.
I just double checked it to make sure, as sometimes what I thought I had done to fix something may not always be where I ended up  Confused
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 Apr 2009 at 1:00pm
Thanks, I will try to keep it in mind, but as you are probably aware, I don't create any stand alone reports, they are all fed from stored procs that create XML files, so this is not really a concern.
 
It is interesting though, I would have thought that it wouldn't work, but I will take both of your words that it does.
 
Thanks, again.
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