Link to home
Start Free TrialLog in
Avatar of dis1931
dis1931

asked on

How to pass a default value (formula) to a SQL command Parameter?

I have a report that uses a SQL command exclusively.  It doesn the querying in the command and there is one parameter which is a date as a string.  In testing I was typing in the parameter manually each time I ran the report.  Now I am done testing and want to have the report run automatically for the previous day usually would use a TOTEXT(CurrentDate-1, "YYYYMMDD") in the record selection.  I don't have the opportunity to do that now that I am using a sql command with a paramter.  So how do I pass in this default behavior.  I know I could go in and edit the query to generate the date that way without a parameter but that means I need to have one report that defaults to this behavior in the SQL command and another that just uses the prompt for a user to run any given day.

I know the default would still be the same but my goal is to have the user do both while not needing two reports and not needing them to have to change the SQL command at all.

Any ideas.
Avatar of Mike McCracken
Mike McCracken

If you have a parameter the user will have to provide a value or you will through an application that runs the report.

Crystal requires a parameter value for all parameters.

CR2008 added OPTIONAL parameters so the parameter doesn't need a value and a new method HasValue you can use to test if the parameetr has a value.

mlmcc
Avatar of dis1931

ASKER

I guess more specifically I am trying to schedule the report from Crystal Enterprise and would like to be able to pass a parameter that is calculated in some way so that I can specify the previous day.  Otherwise if there is now way to do this I will change the query to generate the previous day automatically and then have two reports the one scheduled and the one I let users run for a specific day.
I don't think you can do that in CE though I may be wrong.  I haven't used CE.

mlmcc
You can convert the SQL Command to a stored procedure. Both are conceptually same. With the stored procedure, the Crystal can accept the null parameters and you can have logic built into your procedure for the Stored procedure parameter to use the default value when the parameter is null.
Then in CE you can schedule the report to run automatically with null parameters..

let me know if you have any questions..
hth..
Gary
Avatar of dis1931

ASKER

I agree I've done that on the SQL Server side in the past but in this case it is an Oracle database and I don't manage it and therefore can't get the stored procedure in place....I know it is the same but painful to say the least and then if I need to update it, etc....  

Great idea though!
ASKER CERTIFIED SOLUTION
Avatar of crgary_tx
crgary_tx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dis1931

ASKER

Thanks for the help.  I haven't actually moved it into a Container report...but it is a good idea and depending on how often I get asked to change the report I will do this