Null when using Jasper report list component? - jasper-reports

When select field and adding it to list component in jasper report it can't display values from database it return null
Query for it data set
SELECT TRAFFIC."DESC", INC.UNBILLED_AMOUNT FROM INC_CONTRACT_USAGE INC
INNER JOIN TRAFFIC_SERVICE TRAFFIC ON TRAFFIC.TRAFFIC_SERVICE_ID = INC.TRAFFIC_SERVICE_ID
WHERE INC.TRAFFIC_SERVICE_ID IN (1,2,3)

Related

Postgres get null if row doesn't exist in where clause

I've a postgres table with data like
Name
Attendance
Jackie
2
Jade
5
Xi
10
Chan
15
In my query I want all present by name, and if name doesn't exist return "null" instead of no row for that particular name
Eg
query where Name in ('Jackie', 'Jade', 'Cha', 'Xi')
Should return
Name
Attendance
Jackie
2
Jade
5
NULL
NULL
Xi
10
To produce the desired rows, you need to join with a table or set of rows which has all those names.
You can do this by inserting the names into a temp table and joining on that, but in Postgres you can turn an array of names into a set of rows using unnest. Then left join with the table to return a row for every value in the array.
select attendances.*
from
unnest(ARRAY['Jackie','Jade','Cha','Xi']) as names(name)
left join attendances on names.name = attendances.name;

MDX: Top 10 with filtered members

I'm creating a report for JasperServer in iReport. I am creating a report with the top 10 companies with most product downloads of the selected products. Users can select in JasperReports which products with a list (parameter {$P{ProductFormat}}).
My dimension for products has the following structure: [Product].[ProductFactory].[ProductType], so input for the parameter for example can be: [Product].[ProductCategory1].[Product1], [Product].[ProductCategory2].[Product2], ... I also want those products available as rows so I can use them as fields in iReport. (product in where is not an option)
SELECT
NON EMPTY {
[Measures].[Orders]
} ON COLUMNS,
NON EMPTY
Crossjoin({TopCount({[USER_COMPANY].[Company].Members}, 10, [Measures].[Orders])}, {$P{ProductFormat}})
ON ROWS
FROM [Products]
WHERE $P{DateFilter}
This query return the top 10 companies of all products with the data filtered per products. I want a top 10 companies of the selected products, but I can't get it to work with topcount and as a row.
This query against AdvWrks via SSMS seems to work ok:
WITH
SET [ProductFormat] AS
{
[Product].[Product Categories].[Category].[Bikes]
,[Product].[Product Categories].[Category].[Clothing]
,[Product].[Product Categories].[Category].[Components]
}
SELECT
[Measures].[Reseller Sales Amount] ON 0
,Generate
(
[ProductFormat]
,
[Product].[Product Categories].CurrentMember
*
TopCount
(
[Geography].[Geography].[City].MEMBERS
,5
,[Measures].[Reseller Sales Amount]
)
) ON 1
FROM [Adventure Works];
It returns the following:
If I add a WHERE clause like the following then it seems to be context aware:
WHERE [Date].[Calendar].[Calendar Year].&[2006];

Crystal Report - Conditional selection of record

I'm using Crystal Reports XI.
My data is coming from a dataset.
I have 2 tables which are related as follows:
Product(ProdID(PK), ProdName)
ProdPC(ProdPCID(PK), ProdID(FK), PCType, ProdCode)
The 'PCType' field determins the type of barcode format the 'ProdCode' represents. (E.g. EAN13, EAN8).
In crystal reports one 'Product' can have more than one kind of barcode which means my tables end up looking like this:
Product: ("1", "Example Product 1")
ProdPC: ("0", "1", "EAN8", "01234567"), ("1", "1", "EAN13", "012345678910")
In crystal reports I only want to print 1 barcode label for per product. However because they're are 2 records in the 'ProdPC' table, I will get 2 labels being printed for this 1 product.
What I want to do is place a condition in crystal reports which states, "If EAN13 is NULL then display EAN8, ELSE display EAN13"
I do not have access to the dataset and cannot prevent the application which calls Crystal Reports to create the barcode labels from sending more than 1 record for the 'ProdPC' table.
How can I create my conditional statement, purely in 'Crystal Reports 2008'?
What I have tried so far is:
IF {PartPC.PCType} = "EAN-13" AND {PartPC.ProdCode} <> "" THEN
{PartPC.ProdCode}
ELSE
/* DISPLAY PartPC.ProdCode containing EAN8 value */
;
But I am unsure how to then tell Crystal Reports to display the 'ProdCode' value where 'PCType' is equal to 'EAN8'
Group your report by Product ID.
Order your report by PC Type descending (within Product ID).
Include your report details in the Product ID footer (not the details section).
Option I: create two columns: one for each bar code. Do this in Crystal Reports.
Remove the PartPC table, replacing it with two SQL Expression fields:
// {%EAN-8}
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-8'
)
// {%EAN-13}
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-13'
)
Then create a formula field to display the appropriate one:
// {#barcode}
If Not(Isnull({%EAN-13})) Then
{%EAN-13}
Else
{%EAN-8}
Option II: alter the SQL to create to scalar-valued fields. Do this in your dataset or in a Command object (Crystal Reports).
SELECT Product.*,
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-8'
) EAN_8,
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-13'
) EAN_13
FROM Product
...

Traverse Ireport Input control paramter of type collection(mutiselect parameter)

I have a Oracle query where I want to check content of a Ireport input control parameter of data type "collection" like below the SQL
select devlocview.floorname FROM AlarmDeviceView alrmDevView INNER JOIN devicelocationview devLocView ON devlocview.oid=alrmdevview.deviceoid
LEFT OUTER JOIN DEVICEGROUPVIEW devGrpView ON devlocview.oid=devgrpview.deviceoid
LEFT OUTER JOIN RackCapacityView rackCapView ON devlocview.RACKID=rackCapView.oid WHERE
(
( $P{building.name} IS NOT NULL AND devlocview.buildingname = $P{building.name} )
OR
( $P{building.name}='All Buildings' AND devlocview.buildingname IN (SELECT buildingname FROM cdmr.devicelocationview ) )
)
AND $X{IN, devlocview.floorname, floor.name}
Here
"floor.name" is the multiselect(collection type) inputcontrol parameter of Ireport which contains the value selected by the user in UI
"devlocview.floorname" SQL query output
Now I want to do something like
IF USER SELECTS "ALL BUILDING" IN UI i.e. IF floor.name contains "ALL BUILDING"
THEN DO SOMETHING
ELSE
THEN DO SOMETHING
The problem I am facing is I am not able to traverse and check the contents of Ireport Input control parameter "floor.name" which is of type "collection"

Crystal Report with multiple datasources, one is empty

I have a Crystal report with a table as a datasource and I want to include another table with details for the report footer.
I have two data sources in the report which are not linked, but when the selection criteria returns no rows from the main table, the results from the non-empty non-linked source are also empty.
I suspect it's doing a cross join between the two datasources, so if one is empty, that joined with another is also empty. The problem is I need my rows from the non-empty table to show in the report footer section, and they're getting suppressed by the other, empty datasource.
How can I get rows from an independent table to show in the report footer when the selection criteria and their parameter choices return an empty result set in the main table?
Thanks for your help,
-Beth
Also, I tried using a command as a datasource with sql like this:
select * from waitlist
union all
select distinct null as reportID, null as ..., lastupdated
from waitlist
but it still returns null for lastupdated and suppresses the subreport in the report footer.
I ended up setting my report datasource to a view which unioned another row to the table. I also needed to change my selection criteria so it allows this row to pass through.
Here's my datasource:
CREATE VIEW [dbo].[vw_rpt_waitlist] AS
select * from waitlist
union all
select distinct
reportID,
null as (fields...),
lastupdated,
'reserved' as countyName
from
waitlist
and here's my record selection formula:
({vw_rpt_waitlist.countyName} = {?County} or
{vw_rpt_waitlist.countyName} = "reserved") and
{vw_rpt_waitlist.reportID} = 14
I'm also suppressing the detail section if there were real rows returned:
formula = {vw_rpt_waitlist.countyName} = "reserved"
and to get the parameterized county name they selected in the page header of the report, I'm using:
dim t as string
dim c as string
if {vw_rpt_waitlist.countyName}="reserved" then
c = {?County}(1)
else
c = {vw_rpt_waitlist.countyName}
end if
t = "Waitlist by " + {#serviceTitle} + " and Waiver Need Index as of "
+ cstr({vw_rpt_waitlist.lastUpdated},"MM/dd/yyyy")
formula = t
Since the 'reserved' county always comes through, the subreports are not suppressed.