Crystal Reports - Adding a parameter to a 'Command' query - crystal-reports

Crystal Version - Crystal Reports 2008
Business Objects - XI
I have written a query to populate a subreport and want to pull in a parameter to that query based on input from a user. My question is, what is the correct syntax I need to put in the first line of the 'Where' clause to accept the parameter?
Here is the query I am using in Crystal Reports:
Select
Projecttname,
ReleaseDate,
TaskName
From DB_Table
Where
(Project_Name like {?Pm-?Proj_Name})) and
(ReleaseDate) >= currentdate

When you are in the Command, click Create to create a new parameter; call it project_name. Once you've created it, double click its name to add it to the command's text. You query should resemble:
SELECT Projecttname, ReleaseDate, TaskName
FROM DB_Table
WHERE Project_Name LIKE {?project_name} + '*'
AND ReleaseDate >= getdate() --assumes sql server
If desired, link the main report to the subreport on this ({?project_name}) field. If you don't establish a link between the main and subreport, CR will prompt you for the subreport's parameter.
In versions prior to 2008, a command's parameter was only allowed to be a scalar value.

The solution I came up with was as follows:
Create the SQL query in your favorite query dev tool
In Crystal Reports, within the main report, create parameter to pass to the subreport
Create sub report, using the 'Add Command' option in the 'Data' portion of the 'Report Creation Wizard' and the SQL query from #1.
Once the subreport is added to the main report, right click on the subreport, choose 'Change Subreport Links...', select the link field, and uncheck 'Select data in subreport based on field:'
NOTE: You may have to initially add the parameter with the 'Select data in subreport based on field:' checked, then go back to 'Change Subreport Links ' and uncheck it after the subreport has been created.
In the subreport, click the 'Report' menu, 'Select Expert', use the 'Formula Editor', set the SQL column from #1 either equal to or like the parameter(s) selected in #4.
(Subreport SQL Column) (Parameter from Main Report)
Example: {Command.Project} like {?Pm-?Proj_Name}

Select Projecttname, ReleaseDate, TaskName From DB_Table Where Project_Name like '%{?Pm-?Proj_Name}%' and ReleaseDate >= currentdate
Note the single-quotes and wildcard characters. I just spent 30 minutes figuring out something similar.

Try this:
Select Project_Name, ReleaseDate, TaskName
From DB_Table
Where Project_Name like '{?Pm-?Proj_Name}'
And ReleaseDate >= currentdate
currentdate should be a valid database function or field to work. If you are using MS SQL Server, use GETDATE() instead.
If all you want is to filter records in a subreport based on a parameter from the main report, it might be easier to simply add the table to the subreport, and then create a Project_Name link between the main report and subreport. You can then use the Select Expert to filter the ReleaseDate as well.

Related

Set command parameter of a subreport equal to a main report parameter

In my main report, I insert a number for column ID into the selection criteria. It grabs all relevant information where the ID matches.
Now I have a subreport that uses a COMMAND with a SQL Query. Inside, there is a WHERE clause where ID = {?PM-ID}.
How can I configure my SQL Query to pull in the specific ID value I entered into the selection Criteria of the main Report?
Try this, right click on Subreport > Change Sub reports Links
In that window you have to match the ID with the respective column in your sql query.

how to avoid cascading in ssas parameters in ssrs report and load default "all" when report loads?

i have a ssrs report which uses ssas data source and all of the parameter in report also come from ssas data source. the problem is parameters are acting as cascading parameters. i can not have values in parameter drop-down until i select parameter from previous drop-down.
i wanted to have default value "All" selected when report loads instead of waiting for selecting first parameter and then load subsequent?
i have removed #parameters from parameter data source and now here is how my MDX looks like:
WITH MEMBER
[Measures].[ParameterCaption] AS [Category].[Category ID].CURRENTMEMBER.MEMBER_CAPTION MEMBER
[Measures].[ParameterValue] AS [Category].[Category ID].CURRENTMEMBER.UNIQUENAME MEMBER
[Measures].[ParameterLevel] AS [Category].[Category ID].CURRENTMEMBER.LEVEL.ORDINAL
SELECT
{
[Measures].[ParameterCaption],
[Measures].[ParameterValue],
[Measures].[ParameterLevel]
} ON COLUMNS ,
[Category].[Category ID].ALLMEMBERS
ON ROWS FROM
( SELECT ( [OwningEntity].[Entity ID] )
ON COLUMNS FROM
( SELECT ( [Organization].[Organization] ) ON COLUMNS FROM [PerformanceScores]
))
Create Additional data source , point your first parameter with default value "from query" to that data source - This parameter need to be on the top of the list as in SSRS order of parameters is important.
- Let me know if you got any problems.
Thanks
Daniel
Create hidden parameter with IIF statement in default value.
in IIF put dummy date - this will not execute the report but will fill all the other parameters.
IIF(yourparameter.value="",dummydate.value,yourparameter.value)
Use this hidden parameter as your "Main" data range but default value will depend on visible parameter value in IIF statement when user can choose the range
This should work...

Crystal Report Parameter Link to Sub Report with Command field

I have a main Crystal report which consists of several sub-reports, I managed to link the parameter from main report to sub-report by following this simple steps:
create a parameter ParamOP in main report
insert a sub-report in the main report
right click on sub-report > Change sub report links
select the parameter ParamOP from the "Available fields" window and add to "Fields to link to"
you will notice it will be automatically populated in the "Subreport parameter fields to use" link it to the sub-report field, then click OK
Now, since my sub-report has a command field, how can I display the record in sub-report using the parameter?
Here's my SQL query inside the command, however no data was displayed.
SELECT *
FROM CONFORMEREPORTS
WHERE COVERAGEHEADER = '{Pm-?paramOP}'
ORDER BY [LINENO] ASC

Crystal Report 2008 Add Command Where Clause parameter

Crystal Version - Crystal Reports 2008 Business Objects - XI
I have written a query to populate a subreport and want to pull in a parameter to that query based on input from a user. My question is, what is the correct syntax I need to put in the first line of the 'Where' clause to accept the parameter?
I created a parameter in Add Command it is called PickDate
Here is the query I am using in Crystal Reports:
select
table2.book_no,
table2.time_stamp,
table2.restdate,
a.timestamp,
a.event_type,
a.status,
a.people,
a.new_date,
a.comments,
a.operator_id
from table1 a, table2
where table1.book_no = table2.outage_no
I have tested the query, it is pulling all the data, now I just need help adding parameter to prompt user to enter datatime.
Did you try using the Select Expert in the subreport? You should be able to say field = {?PickDate}

SSRS two datasets need to use field from one dataset as a parameter in second?

The issue is that the in field that has the data is just one record in the data set pulled from a set stored proc (not touchable).
Then using it as a parameter in the second dataset. Any help would be appreciated.
Add parameter
Select parameter visibility as Hidden
Go to Default Values: (Screenshot of below)
Select "Get values from a query" (and select your first dataset and value field)
In Dataset 2 filter the data with your new parameter
i.e. SELECT * FROM XYZ WHERE ABC IN (#Param)
You can do this using a subreport.
Add a subreport to the main report.
Add a parameter to the subreport.
Open the rdl of the subreport, add a paramter with the same name.
create a dataset in that RDL using your query for example
select * from YourTable where ENTY_KEY = (#param)