Solved

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

Posted on 2008-10-21
7
1,921 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal Reports Sub Report 4 85
Crystal Reports maximum report processing jobs limit error 2 45
Exclude some records from totals 10 56
Crystal Reports get subgroup count 1 50
1. Set up your parameter at the report level as usual, check the box Multi-value, and set the Data Type to String 2. Set the Stored Procedure Parameter to varchar(max)  --<---- This part here is the key to it's success Example:    @cst_key var…
Hello, In my precious Article  (http://www.experts-exchange.com/Database/Reporting/A_15280-Create-Project-in-Microstrategy-Part-I.html)we saw the Configuration part for Microstrategy which included Metadata Creation and DataSource Preparation as …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 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