Solved

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

Posted on 2008-10-21
7
1,935 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, I am very much excited today since I'm going to share something very exciting Tool used for Analytical Reporting and that's nothing but MICROSTRATEGY. Actually there are lot of other tools available in the market for Reporting Such as Co…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 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