Solved

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

Posted on 2008-10-21
7
1,864 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 …
How to increase the row limit in Jasper Server.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

21 Experts available now in Live!

Get 1:1 Help Now