I want to create a report and filter it by two parameters as below;
Parameter values are;
Call_type = "All" , "Sale" , "Buy"
and
Call_status = "All" , "Sold" , "Pending" , "None" , "Closed"
I have used below formula;
(
if {?type} <> "All" then
{cars_call_log.type} = {?type}
else
true;
);
(
if {?status} <> "All" then
{cars_call_log.status} = {?status}
else
true;
);
But it will work only for first If condition. It doesn't work for both conditions.
I want to make it like, Filter by first parameter then (filtered records)--> filter by second parameter.
The proper, record-selection-formula syntax for your needs:
(
if {?type} <> "All" then
{cars_call_log.type} = {?type}
else
true
)
AND
(
if {?status} <> "All" then
{cars_call_log.status} = {?status}
else
true
)
Related
Is there any other way to use a table name as a function parameter in PostgreSQL than with Execute?
The problem is the existing statement (taken from a report in openMaint) is long and has a lot of existing variables.
I want to be able to make a general function that can be used for any similar report where all I need to do is pass the different table parameters instead of making a new function for each report. However things will get exceedingly complicated using Execute. Does anyone have any alternatives for me?
CREATE TEMP TABLE "ReportData" AS
SELECT lang,
coalesce((SELECT "Description" FROM "Site" WHERE "Id" = site_id), '')::varchar site_descr,
coalesce((SELECT "Description" FROM "Division" WHERE "Id" = divis_id), '')::varchar div_descr,
coalesce(cons."Description", '')::varchar consb_descr,
coalesce(cat."Code", '')::varchar cat_code,
coalesce(_cm3_translation_lookup_get(cat."Id", lang), '')::varchar cat_descr,
coalesce(_cm3_translation_lookup_get(scat."Id", lang), '')::varchar scat_descr,
coalesce(ssite."Description", '')::varchar srcsite_descr,
coalesce(sdiv."Description", '')::varchar srcdiv_descr,
coalesce(dsite."Description", '')::varchar dstsite_descr,
coalesce(ddiv."Description", '')::varchar dstdiv_descr,
coalesce(to_char(wrmov."Date", 'DD TMMon YYYY'), '')::varchar wm_date,
coalesce(wmrow."Quantity", 0.00)::numeric wmr_quantity,
(CASE WHEN site_id IS null THEN
CASE cat."Code"
WHEN 'Load' THEN '+1'
WHEN 'Relocation' THEN '0'
WHEN 'Unload' THEN '-1'
ELSE null
END
ELSE
CASE WHEN (wrmov."SrcSite" IS null OR wrmov."SrcSite" != ALL(sites_set)) AND wrmov."DstSite" = ANY(sites_set) THEN '+1'
WHEN wrmov."SrcSite" = ANY(sites_set) AND wrmov."DstSite" = ANY(sites_set) THEN '0'
WHEN wrmov."SrcSite" = ANY(sites_set) AND (wrmov."DstSite" IS null OR wrmov."DstSite" != ALL(sites_set)) THEN '-1'
ELSE null
END
END)::varchar qt_symbol
FROM "GAWrhMovement" wrmov
LEFT JOIN "LookUp" cat ON cat."Id" = wrmov."Category"
LEFT JOIN "LookUp" scat ON scat."Id" = wrmov."Subcategory"
LEFT JOIN "Site" ssite ON ssite."Id" = wrmov."SrcSite"
LEFT JOIN "Division" sdiv ON sdiv."Id" = wrmov."SrcDivision"
LEFT JOIN "Site" dsite ON dsite."Id" = wrmov."DstSite"
LEFT JOIN "Division" ddiv ON ddiv."Id" = wrmov."DstDivision"
JOIN "GAWrhMovementRow" wmrow ON wmrow."WrhMovement" = wrmov."Id" AND wmrow."Status" = 'A'
LEFT JOIN "GAConsumable" cons ON cons."Id" = wmrow."Consumable"
WHERE CASE WHEN site_id IS null THEN true ELSE (wrmov."SrcSite" = ANY(sites_set) OR wrmov."DstSite" = ANY(sites_set)) END
AND CASE WHEN divis_id IS null THEN true ELSE (wrmov."SrcDivision" = ANY(divis_set) OR wrmov."DstDivision" = ANY(divis_set)) END
AND wrmov."Status" = 'A'
ORDER BY consb_descr, wrmov."Date";
No, there is no other way than to use dynamic SQL with EXECUTE.
IIF(
[Parameters].[Year] = 'All'
, 1=1
, [Parameters].[Year] = STR(YEAR([Date]))
)
tableau if parameters return no match than return 0
Try this, will return 1 when finds a value, 0 when it doesn't
INT([Parameters].[Year] = 'All' OR [Parameters].[Year] = STR(YEAR([Date])))
I have a package. Package includes a list of items. Item has a list of fields. I need to check if specific fields are set to correct value for all items in a package:
rule "Slapper"
dialect "mvel"
when
itm : item( ) from pkg.items
List( size() == itm.size() ) from collect (
field( fieldId == "111" , value == "1" ) from itm.fields
field( fieldId == "222" , value == "2" ) from itm.fields
) from itm
then
...
end
how I can get collection filtered by subfields?
Need to use accumulate function:
List( size == pkg.items.size() ) from accumulate (
$a: itemData( $field1: fields, $field2: fields ) from pkg.items
and
fieldData( fieldId == "111" , value == "1" ) from $field1
and
fieldData( fieldId == "222" , value == "2" ) from $field2;
collectList( $a )
)
I have the following in my selection expert:
(
if {?Job} <> "All" then
{SPSYSPRO_PO_CapexJobs;1.MJob} = {?Job}
else
true
) OR
(
if {?Supplier} <> "All" then
{SPSYSPRO_PO_CapexJobs;1.MJob}= {?Job}
else
true
)
However its not doing what I want ^^
What I require is if Job has not value selected then use the supplier's list to obtain data.
So if Job has no value and Supplier = multiple values it should bring me all those suppliers jobs, or vice versa...
If I select Job = All and choose multiple supplier's it should bring me back all jobs for just those suppliers selected and vice versa...
Hey just thought ill add my SP here, then you might understand what im looking for as your formula don't work in this regard.
SELECT SUBSTRING(PD.PurchaseOrder,9,7) PurchaseOrder
,PD.[Line]
,PD.[MStockCode]
,PD.[MStockDes]
,PD.[MOrderQty]
,PD.[MReceivedQty]
,SUBSTRING(RD.Supplier,9,7) Supplier
,AP.SupplierName
,PH.OrderEntryDate CreateDate
,PH.OrderStatus
,PD.[MLatestDueDate]
,PD.[MLastReceiptDat]
,PD.[MDiscValue]
,PD.[MPrice]
,PD.[MForeignPrice]
,PD.MJob
,PD.[MRequisition]
,PD.[MRequisitionLine]
FROM [SysproCompanyR].[dbo].[PorMasterDetail] PD
INNER JOIN [SysproCompanyR].[dbo].[PorMasterHdr] PH
on PD.PurchaseOrder = PH.PurchaseOrder
INNER JOIN [SysproCompanyR].[dbo].ReqDetail RD
on PD.MRequisition = RD.Requisition and PD.MRequisitionLine = RD.Line
INNER JOIN [SysproCompanyR].[dbo].ApSupplier AP
on RD.Supplier = AP.Supplier
Where SUBSTRING(PD.MJob,1,1)= 'C'
and PD.MCompleteFlag <> 'Y'
and PH.OrderStatus <> '*'
if you need only jobs for the suppliers that are selected then it would be better you use the sub report
In main report create a parameter for suppliers and jobs and pass suppliers parameter to sub report and link job parameter in main report to sub report
using sub report links and write the below formula in sub report record selection formula
For parameters create 2 default values All, None and your normal list
if {?Job} = "All" and ({?suppliers} <> "ALL" and {?suppliers} <> "none") then
{SPSYSPRO_PO_CapexJobs;1.MJob} = {?Job} and
{SPSYSPRO_PO_CapexJobs;1.Msuppliers} in ("list of comma saperated suppliers")
//For above case you need to have relation between jobs and suppliers
else if
(({?Job} = "All" or {?suppliers} = "none") and {?suppliers} <> "ALL")
then {SPSYSPRO_PO_CapexJobs;1.MJob} = {?Job}
else if
({?Job} <> "All" and ({?suppliers} = "ALL" or {?Job} = "none"))
then {SPSYSPRO_PO_CapexJobs;1.MJob}= {?Job}
if you don't want to use the sub report then retrieve all records and do the selection in crystal reports
if
(({?Job} = "All" or {?suppliers} = "none") and {?suppliers} <> "ALL")
then {SPSYSPRO_PO_CapexJobs;1.MJob} = {SPSYSPRO_PO_CapexJobs;1.MJob} else if
({?Job} <> "All" and ({?suppliers} = "ALL" or {?Job} = "none"))
then {SPSYSPRO_PO_CapexJobs;1.MJob}= {SPSYSPRO_PO_CapexJobs;1.Supplier}
Hope it helps
I'm working on a report in Crystal Reports XI that allows someone to filter help desk tickets using a number of optional dynamic parameters. If I make a selection for each parameter it returns the expected results, but if I leave out any of the parameters it doesn't return anything and when I look at the SQL query it says, "No SQL Query is used because the record selection formula returns no records." I currently have the following code for Record Selection:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
)
and
If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
)
and
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
)
and
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
)
To me, this seems like it should work and if I leave out the If statement to verify the parameters have values I get an error so it seems like the HasValue is working properly. Any ideas?
Your problem stems from not explicitly handling the optional parameter configurations. It's easy to run into this problem when using if-statements in the record selection formula. Instead, explicitly handle the cases where the parameters DO and DO NOT have values. Something like this:
...
(not(hasvalue({?Group})) or {Groups.Code}={?Group})
and
(not(hasvalue({?Category})) or {Incident.Subject Description} = {?Category})
and
(not(hasvalue({?Staff})) or {Incident_Details.Login ID} = {?Staff} )
and
(not(hasvalue({?Community})) or {Incident.Company Name} = {?Community})
Doing it this way effectively tells CR to just ignore the parameter if is doesn't have a value, otherwise select records based on what was entered in those parameters.
The Record Selection formula indicates whether a record must be used, or not, by returning true or false. With that in mind, if some value is informed, the formula must return True if it meets some criteria. If nothing is informed on the filter, the formula must always return True.
Try something like this:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
(If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
) else
(True))
and
(If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
) else
(True))
and (
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
) else
(True))
and (
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
) else
(True))