Set command parameter of a subreport equal to a main report parameter - crystal-reports

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.

Related

Generate table report using sql joins in iReport

SELECT a.CIVIL_ID,a.PAT_NAME,a.SEX,a.PAT_NAT_CD,a.BIRTH_DT,a.ADDR,a.MOBILE_NO,b.FILE_NO,b.CREATED_DATE
FROM PAT_MST a
JOIN PATIENT_FILE b ON (a.PATIENT_ID = b.PATIENT_ID)
AND( b.HOSP_DEPT_SEC_SERIAL = $P{P_HOSP_DEPT_SEC_CD})
AND a.SEX = DECODE($P{P_GENDER},'ALL',a.SEX,$P{P_GENDER})
AND TRUNC(B.CREATED_DATE)>= TO_DATE($P{P_FILE_CR_DT_FROM},'DD/MM/RRRR') AND TRUNC(B.CREATED_DATE) <= TO_DATE($P{P_FILE_CR_DT_TO},'DD/MM/RRRR')
I am using this query to generate a table report in iReport(5.6.0), but for some reason I am only getting the column headers but this query is returning records when I run on toad.
Please tell where I am wrong..
Are you using Table report element? If so, you are using not the main dataset but some other subdataset. You should transfer parameters values from the main dataset to the one of which your table "feeds".
Add to your subdataset a parameter for an every parameter, used in main dataset.
Right click on your table Edit table dtasource->select Parameters tab->click Add.
In the Add/modify parameter window select your subdataset parameters in the upper menu. In the lower menu select their values (correspondent parameter from main dataset). Do this for an every parameter.

Crystal scanning all record regardless of date parameters passed

I have created a report that has a start and end date parameter. These are created and referenced in the where query. They work fine in the main report, but even when I link them to the subreport, the subreport keeps looking through all the fields and take too long to launch. Any suggestion how can I make the sub-report too look for records in the specified range only?
I have created the links with the Select data in subreport based on field, unchecked and the select expert formula is set as shown below
{Command.program_code} = {?Pm-Command.program_code} and
{#appointment_date} in {?Pm-?from} to {?Pm-?to} and
{Command.SITEID} = {?Pm-Command.SITEID}

SSRS: How to Page Break between Row Grouping on uniqueidentifier?

I am developing an SSRS 2008R2 report and I have a tablix. Within this tablix there is a Row group on a uniqueidentifier field. This row grouping works correctly by showing one row per uniqueidentifier. But now I want it to page break. However, when I try to page break on this group it gives me an error since this row group is based on an uniqueidentifier field vs. other data type.

Crystal Reports sort by subreport

So I have a series of orders that come in everyday. We add them to a database and then use Crystal Reports make packing sheets of these orders. We have two tables one for order information(name, address, order number, etc) and one for the items. In Crystal Report we use the order for the report and then do a subreport with all the item associated with order number. Now I have been given the requirement that we need to all the orders sorted by the first item's item number. How do I sort a report by a field in a subreport?
First of all, you can accomplish this report w/o a subreport. The report would be grouped by order # w/ the order fields in the group header. The Details section would contain the order-items.
In any case (my approach or yours), if you just need to sort the order-items by item number, simply reference that field in the Record Sort Expert.
If you need to sort the orders by each order's order-items[0] (the first item in the list), you'll need to create a SQL Expression that returns the item #. If you add a group on the SQL Expression field, then make that the top-level group (G1), the report will group first by the SQL Expression, then by the Order #. The SQL Expression should resemble:
(
//this will select the numerically-smallest item# for a given order#
SELECT min(item #)
FROM order-items
//correlate to 'main' query
WHERE order#=order.order#
)
If you need more complex rules for 'first item #' (whatever that means), you need to include it in the SQL Expression.

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

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.