I have a report, and the report has 5 subreports. There is a parameter named "SubreportNumber". I want to run one of the subreports, based on that parameter. Just one of them should run. Effectivity is important in my case. Is this possible?
I'm using an IIF statement to hide (using visibility) my reports based on a parameter value, as described above.
Then I take the same approach when specifying the sub-report parameters.
This can basically be done on any one of the parameters, if the report should be showing then pass the parameter, else pass nothing. (If you pass NOTHING as a parameter to the report, it won't run the report, ie. performance increase...)
Example for Year parameter below:
=IIF(Parameters!SubreportNumber.Value = "1","YEAR(NOW)", Nothing)
You can hide the reports you dont want based on your parameter.
To do this: Go the Report's property, under visibility section. Set Show or hide report based on expression. You can write an expression to hide report depending upon your parameter.
This will just hide the reports. Make sure there are no stored procedure or they will be execute irrespective or whether the report is visible or not.
Related
Using Crystal Reports XI, I have a main report. In this report, I have a Formula Field named XXXCompanyFilter. This is set programmatically at run time and I want to pass it to a subreport.
I add a subreport that has a stored procedure as an input parameter. The parameter is named #co.
A Parameter Field is automatically created in my subreport called #co.
I return to my main report and right-click the subreport and choose Change Subreport Links. I choose the Formula Field XXXCompanyFilter from the Available Fields list and move it to the Field(s) to link to: list.
At this point I expect to be able to choose the subreport's #co parameter in the Subreport parameter field to use: drop down, but it is not there. I have unchecked the Select data in subreport based on field: checkbox.
I've tried selecting the ?Pm-#XXXCompanyFilter option, and that (I think) causes a new subreport parameter to be created:
After that, I do get the new subreport parameter to show in the drop down:
However, this new parameter doesn't seem to do anything, and I'm still prompted to enter the #co subreport parameter whenever I run the report. If I enter a value for the #co parameter the report returns the data I expect.
I've created several subreports to see if the behavior changes. I've tried it with the subreport wizard and with subreports I've created normally. I always get a 2nd, non-useful subreport parameter and the #co parameter is never set, so I am prompted for it.
I feel like if I could select the #co parameter in the drop down list it would work as needed.
I've checked out multiple SO posts, and I've googled the issue but everything I find says I'm doing it right. What am I doing wrong, or what do I need to do to make the #co parameter available in the drop down?
I solved this by specifying a database field in the Available Fields list when creating the subreport link and following the instructions in my original post.
Apparently it just won't work if you specify a Formula Field in the Available Fields list. I can't find any documentation on this but that's the conclusion I come to after reaching a solution by trial and error.
I have done this before, where the main report's parameters are passed on to the subreport. Currently, there are 2 parameters from the main report being passed to my subreport, but I need to add 2 more. When I go through the "Change Subreport Links" option and select and add the needed parameters, it simply doesn't save. I am not sure how else to add these.
Steps:
create desired parameters in sub-report
create corresponding parameters in main report
link with 'linking expert'
The datatypes of the parameters fields did not match, so the two were not correlating.
I'm using Crystal reports designer Version 11.
I have a report which calls a subreport and I have set up linked parameters.
The subreport is using a stored procedure.
I can't see how I feed to the parameters passed to the sub report into the stored procedure that is returning the data.
This is really late to the party, but I'm researching the same problem (I think) and have found a solution. In the main report, right-clck on the sub report and "Change Subreport Links".
In the top section, choose your parameter in the main report and click the right arrow to add to the "Field(s) to link to". In the bottom, sub-report section of the window, change the left side "Subreport parameter field to use" drop-down. It defaults to creating a new parameter in the sub report and you don't want to do that. You want to use an existing paramter (that was automatically added by using the stored procedure). In the drop-down choose that parameter that was auto created by the stored procedure.
Doing this means that you can have a parameter in the main report that you can automatically pass to the subreport which means you don't have to enter the same value for two separate parameters.
I hope this helps. It works great for me.
I understand this question is old but have found no satisfactory answer elsewhere. The simple solution I found is to implement the stored procedure from within a crystal command just like any other command sql. I could not get the parameters to show up in the bottom left drop downs no matter what. Something similar to below where ZNG_PROACTIVE_STREET_SWEEPS is the name of the stored procedure and the two parameters are what the stored procedure takes in.
[dbo].[ZNG_PROACTIVE_STREET_SWEEPS] #StartDate ={?begindate}, #EndDate = {?enddate}
After considering and then some searching, I take back my original answer.
Once you have parameters defined for the SQL Command, they are visible/available as parameters from outside the report. When you set up the links from the calling report to the subreport, the subreoprt parameters will be visible and available and you can link fields from the main report to those parameters.
A recent post in someone's blog covers the same activity with subreports driven from SQL Commands
Using SQL Commands and Parameters
I hope this helps and I hope that my original answer did not negatively affect your progress on your report.
Original answer
You cannot pass parameters to a stored procedure from report objects. The stored procedure will respond to CR Designer when you first reference the SP when you define the report. CR creates links to stored procedure parameters from the data source interface only, not from the report.
You will see an entry in the Parameters objects, but it will be read-only -- you can place it in the display section, but you cannot set it from report formulas, passed values, etc. Using formulas to process data before calling the stored procedure will not work, nor will trying to pass data through subreport links from the main report.
Using other design tools, you can have code that controls the data source interface, and processes data that is passed in parameters, but in CR Designer, you are pretty much left with the bare minimum options. You can right-click on the parameter and do things like set default values, set prompting text, set a pattern / mask for the format, but that's about it.
How can i create function to iterate through datatable to read value from table
e.g
Function GetVal(integer id)
//iterate here and match value from table using id
return value;
and call this function on report field
i am using crystal report 11
any clues??
Option 1: Make your function (or equivalent SQL query) outside of Crystal and link to it like any other source. The practicality of this option depends on the details of your report.
Option 2: Crystal doesn't have a built-in Get() function that I can find. So, you'll have to get creative with subreports. For example, let say's say you want to get {TargetFld} from {LookupTable} based on {CriteriaFld}:
Make a subreport. Use {LookupTable} for your data source.
When entering subreport links, choose {CriteriaFld}.
In your subreport, make a formula. Use it to create a Shared variable and set the value to whatever value you want to pass back to the main report.
Position the subreport 1 section above the section where you need to use this value. (Otherwise it won't evaluate when you expect it to).
Create the Shared variable in the main report.
Use it as normal.
If you're not familiar with subreports or shared variables, I suggest first looking them up in the Crystal help files (F11). This will make alot more sense that way.
I am using crystal reports 2008. I want to generate a report for which i will get one value from one subreport and i want to pass this value as a parameter so that i can include this value in the sql command.
For eg.
From my subreport i will get customerkey and i want to pass this value in the sql as
{?customerkey}
Sql is 'select card_number from customers where customerkey={?customerkey}'
For this i created parameter in the command and added like this.
But what my problem is this customerkey is getting from subreport(using shared variable).If i get a value customer_key from subreport how will i assign this value to {?customerkey}. I tried like assighning this value but i dont want to popup {?customerkey}this value as a parameter.
Can anyone help? Please
So you want the data shown in the main report to be based on a parameter passed to it from a subreport? I don't think this is possible - the Report Processing Model (described here) states that SubReports are in 'Pass 2', while data retrieval is in 'Pass 1'. This means that the parameter prompt will always appear first.
You might instead be able to have the main report contain TWO subreports, the first of which is used to retrieve the parameter and the second uses it. That can get very messy, especially when dealing with page headers and footers.