Jasper Reports Group VS Oracle Order By - jasper-reports

I have a report that I am in the process of converting from Crystal Reports to JasperReports. I am designing the report using iReport 4.5 and JasperReport Server 4.5. Oracle Stored Procedure that returns REF_CURSORS is used to populate data. Below is a sample SQL:
Select First_Name, Last_Name, DOB, City From PPL Order By DOB;
When I use this SQL in the report designer and design a report and I create groups as follows
Parent Group is First_Name
Second Group is City
Basically I want to group all the people with similar first name in the all the cities it applies.
Expected results:
First_Name Last_Name DOB City
Alan Kum 10/01/2010 Mumb
Alan Boss 01/10/2001 Mumb
Alan Cross 10/10/2000 Irvn
But since the SQL has an order by clause my data is not displayed in the expected manner as displayed above. How do I overcome this issue?
The issue is I can not change the procedure as it's being used in the application and also an Excel version of the report uses the same query where they want to see the data in order by DOB.

Well... the "correct" solution is to change the query to order by the fields you want to order by: First_Name, City (and then perhaps by DOB or Last_Name to have a fully deterministic ordering).
But since you don't have that option available to you, you can instead do the sorting in JasperReports. Edit your query and then click the button "Sort options...". This should allow you to re-sort the data as you like. It will be slower sorting in the report engine, but slower and correct is far better than a quick result which doesn't meet your needs.

Related

In SSRS, can you group multiple parameter values into one?

I am relatively new to SSRS but have been working with SQL for years. I have been tasked with creating a report that reflects shipped items based on their status. For example, I have x number of items with varying statuses including "IN_TRANSIT", "RECEIVING", "SHIPPED", "WORKING", and "CLOSED". The requestor is asking if I can provide the following options in a report drop down:
"IN_PROCESS" Status filter including all statuses except "CLOSED".
"CLOSED".
Essentially, they want to be able to view all non closed statuses, closed, statuses, or all. Right now, I have it set so you can individually select all statuses, essentially getting them the data they want, just not with the "right" parameters.
My question is, does SSRS provide a way to essentially 'group' the non-closed statuses into one inside the report so that when they select "IN_PROCESS" it sends those non-closed statuses to the SQL query I have built in? The problem with using SQL for this is that the dataset I created to generate the dropdown options provides "CLOSED" and "IN_PROCESS" as it's output options, but when they select "IN_PROCESS" (sending that value to the filter in the report), since it's not an actual status, nothing comes back.
If more information or clarification is required, please let me know.
Thanks ahead of time!
You can create a new column in your SQL query and use a CASE statement to give the value of IN_PROCESS or CLOSED for the applicable status. Then you will just need to the filtering condition to match the SSRS parameter to the new column.
Depending on how often this case is likely to be reused should help determine how to approach it. If it sounds like it might become a regular process.... "Oh can we have another report with the same filter but showing xyz " then take the time to setup correctly and it will save time in the future.
Personally I would add a database table, if possible, that contains the status names and then a status group name (ignoring fully normalising for the sake of simplicity here).
CREATE TABLE StatusGroups(Status varchar(10), StatusGroup varchar(10))
INSERT INTO StatusGroups VALUES
('IN_TRANSIT', 'In Process'),('RECEIVING, 'In Process'),('SHIPPED', 'In Process'),('WORKING', 'In Process'),('CLOSED' 'Closed')
Then a simple view
CREATE MyNewView AS
SELECT t.*, g.StatusGroup
FROM MyTable t
JOIN StatusGroups g on t.STATUS = g.Status
Now change your report dataset query to use this view passing in the report parameter like this...
SELECT *
FROM MyNewView
WHERE StatusGroup = #myReportParameter
Your dataset for your report parameter's available values list could then be something like
SELECT DISTINCT StatusGroup FROM StatusGroups
This way if you every add more status or statusgroup values you can add an entry to this table and everything will work without ever having to edit your report.

Crystal Reports - Using Report Data as Sql Command Parameter

I'm hoping someone here might be able to help me with a Crystal Reports problem that's been bugging me on and off for days.
I have a report that is used as a picking slip for our warehouse staff to tell them which products to pack for each order that comes through our sales system.
The report contains all the products for the order and the quantities that need to be packed in the details section of the report which come from a number of joined tables.
My problem is that I have to then query the database again in order to get the total amount of items for each product on the order that have been packed across all orders throughout the warehouse.
The report datasource only returns records relating to the order on the picking slip so I need a sub query.
I've tried to use a SQL command with the following query:
SELECT ISNULL(SUM(QtyPacked), 0)
FROM tblPackingSlipLines
WHERE Status = 'Packed'
AND ProductId = '[ProductId]'
I'm stuck on passing the product id into the command as it is held in a text field on the report itself which is populated from tblProducts.ProductId (one of the joined tables).
Is it even possible to access this value from the command?
I've tried things like ProductId = '{tblProducts.ProductId}', #ProductId, ?ProductId and numerous other weird and wonderful permutations.
I can't use a parameter as that would require either user interaction; not possible as the report is auto generated by a Windows service or passing a static value in from the service.
I've also tried using a formula but that only pulls back the sum of QtyPacked for that distinct order line and not all packed orders in the DB:
SUM('{tblPickingSlipLines.QtyPacked}', '{tblProducts.ProductId}')
Any help would be greatly appreciated.
try using the sub report for this purpose.
Write your second query in sub report and pass the tblProducts.ProductId to the record selection parameter of the sub report through sub report links now your query comes in sub report as:
SELECT ISNULL(SUM(QtyPacked), 0)
FROM tblPackingSlipLines
WHERE Status = 'Packed'
AND ProductId = {pm-product ID}

Crystal Reports Filter by Most Recent Date of Field

I have a report I am creating through an ODBC connection. The report includes several invoices, where each invoice has several products. There is also a table which contains all the historical price changes for each product (field: unit-price). Currently there are duplicate product records being pulled, one for each time there was a price change. Therefore, I need to filter my data so that only the most recent unit-price is shown (date field: effective-date). How can I do this via the "Select Expert?"
In short, show the product's unit-price for the most recent effective-date.
Thank you!
You'll need to create a sql-expression field to get the most-recent effective date, then use this field in the record-selection formula.
// {%MAX_EFFECTIVE_DATE}
// most-likely you'll need to alias the table in the main report for this to work
(
SELECT Max(effective_date)
FROM price_history
WHERE product_id = price_history_alias.product_id
)
Record-selection formula:
{price_history_alias.effective_date}={%MAX_EFFECTIVE_DATE}
Instead of doing it in select expert. group by effective date and set the ordering as Descending.

How to display individual reports in cyrtal reports

I am new in using crystal reports. I already tried to create a report but it doesn't look like what I wanted. What I want to create is an individual report of each employees where it displays their information like name, age, birth date, address, etc.. But then, crystal reports will display all reports of each employees in a single document. Is there any way that I could make each employees information to display in a single document like I could use an arrow to navigate to next employee information if I want to see their report?
By the way, I used Microsoft SQL R2 in getting data for my reports. Thanks.
hi the question is not clear..as my knowledge i suggest..that if you design
the crystal report of one employee in single document and attach stored procedure to that
report your problem is solved ..you will get every employee details in a serial order this is the answer if i understand your question correctly,if not can you please repeat the questi
on with changes which i can understand
thank you

Show Report group even when no records selected

I'm trying to show employees at a company grouped by worked and still working (in vs2005 crystal reports).
The user can pass by parameter a list of companies they want to show.
Tables: VRP-COMPANY, VRP-COMPANY-OPPORTUNITY, VRP-OPPORTUNITY-PRODUCT
The record selection formula: {VRP-COMPANY.COMPANY company} in {?companies}
Grouping is done on: VRP-COMPANY.COMPANY company, then formula to decide its working or worked and then on productname.
Now when I run the report I only get to see the companies who have got entries in the VRP-COMPANY-OPPORTUNITY. I want to see the company name (group) even if there are no entries in the opportunity table. How to do this in Crystal Reports? I tried Left join between company and company-opportunity tabel but no effect.
I found the problem. Left join was correct but I had an additional select formula (on opportunity status to be closed-won. Therefore it let out the record. The record can also be null when there are no opportunities.
Should the question be deleted?