Solved

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

Posted on 2008-10-21
7
1,895 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:dis1931
  • 3
  • 2
  • 2
7 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 22767887
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
0
 
LVL 10

Author Comment

by:dis1931
ID: 22767962
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.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 22770477
I don't think you can do that in CE though I may be wrong.  I haven't used CE.

mlmcc
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:crgary_tx
ID: 22770734
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
0
 
LVL 10

Author Comment

by:dis1931
ID: 22771820
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!
0
 
LVL 13

Accepted Solution

by:
crgary_tx earned 500 total points
ID: 22776530
Well there is another solution which I have implemented in one of my reports which uses command object having a date parameter.

>Place  the report as subreport inside another blank report (Container!).
>Create a date parameter P_DATE of type STRING in the main report
>Create the following formula say @p_date

if isnull({?P_DATE}) = true or {?P_DATE} = '' then
cstr(date(currentdatetime-1),'yyyy-MM-dd')
else
{?P_DATE}

>Link your subreport date parameter with the above main report formula.

hth..
Gary

Note: TYour command object date parameter should be of type string
0
 
LVL 10

Author Closing Comment

by:dis1931
ID: 31508298
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Problem Statement In an SAP BI BO Integration project when a BO universe is built on a BEx query, there can be an issue of unit & formatted value objects not getting generated in a BO universe for some key figures. This results in an issue whereb…
How to increase the row limit in Jasper Server.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now