I’m building a report using Crystal Reports XI that calls a SQL Server stored procedure that expects parameters @Type_ID and @Subtype_ID.
There’s also a table in the database that associates Types and Subtypes in a one-to-many relationship.
I’d like to have the report’s parameters prompt screen ask for:
-
Type – either one of the listed Types or Null. If Null, the screen won’t ask for a Subtype.
-
Subtype – either one of the listed Subtypes that’s associated with the selected Type or Null.
… and pass these two values to the stored procedure as @Type_ID and @Subtype_ID, respectively. (If the stored procedure gets @Type_ID = Null, it will return records of all types. If it gets @Type_ID <> Null and @Subtype_ID = Null, it will return records of all subtypes associated with the selected type.)
Is there a way to make my Crystal report do all this?
So far, using advice from this answer, I set up a dynamic cascading parameter (DCP) on @Subtype_ID, which asks for a Type and then a Subtype in the way I describe above, then passes the selected Subtype to @Subtype_ID. However, I haven’t yet figured out how to pass the Type selected through this DCP to @Type_ID, so that if Subtype is Null, the stored procedure can return all records with the selected Type.
The problem is that your procedure’s definition creates to two parameters:
TYPE_IDandSUBTYPE_ID. Crystal Reports’ parameters (dynamic or static) weren’t designed to interact with each other.As I see it, you have three options:
create a report w/ the single prompt group (make sure that the prompt group creates two parameters) that you want (the main report doesn’t require a data source, btw); insert a subreport that uses your procedure (it will create two parameters); link the parameters in the main report to parameters in the subreport; if necessary, you can create formulae in the main report (which are then linked to the two parameters in the subreport) for extra logic (convert a parameter value of ‘All Type Id’ to NULL, for example).
refactor your procedure to have a single
VARCHARparameter that will receive a concatenatedTYPE_IDandSUBTYPE_ID. Create a dynamic parameter that will have a concatenated value for the key and for the description (e.g. 1/3; Type [1] – Subtype [3]). Your procedure’s logic will need to parse the parameter’s value to determine the values ofTYPE_IDandSUBTYPE_ID. You’ll need to create a query that generates the keys and descriptions, which will be exposed through a BusinessView’s various layers.abandon the procedure in favor of a Command or ‘normal’ query. in my experience, the vast majority of reports can be build without a stored procedure. Combined w/ a single prompt group, this will give you the flexibility that you need.