If then record selection with multiple conditions - mysql

Using Crystal Reports 2011 to reference a View
My formula written as a "formula field"
#mySelection
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN {V_JOB.JOB} ELSE "FALSE"
My record selection written in the "Record Selection Formula"
{V_JOB.LMO} = 'L' AND
{#mySelection}
This View contains several relevant fields. To make my record selection of the view, I want to display all records that are equal to string in .JOB, when string in .TASK like "*IN" and field .DATE = ?myDateRange and field .CLOSED = 'Y'
so I wrote the equation to do exactly that, but the displayed records are row JOB only when TASK,DATE,CLOSED are true. But I have multiple rows of the same JOB where TASK,DATE,CLOSED is false that I also want to see.
So if there are 30 records for Job A and only 1 of those records has #mySelection is "true" then I want to select ALL 30 records even if the other 29 are "false". The way it is written it only displays the 1 true record and not the other 29.
Can anyone provide some assistance on what I'm doing wrong? Is there a "show all" command or perhaps I can save "true" JOBs in an array and then reference the array as my record selection?

Where abouts are you inputting your formula within crystal? It is very important.
You should be able to achieve what you want by using conditional suppression in the details section of your report. Something like this...
//Untested//
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN False ELSE True
This will suppress results where they do not equate to the above conditions.
I found your question a little unclear so this answer might not be perfect for your needs, but hopefully it's a shove in the right direction.

I was able to accomplish this using a sub-report to record select with a parameter reference from the main report
{V_JOB.LMO} = 'L' and
{V_JOB.JOB} = {?Pm-V_JOB_OPERATIONS.JOB}
Then I created a main report and linking a parameter to Job.Job in the sub report and did a record selection for my criteria in the main report.
{V_JOB.TASK} LIKE "*IN"
{V_JOB.CLOSED} = "Y"
{V_JOB.DATE} >= {?FrDate}
{V_JOB.DATE} <= {?ToDate}
I then put the sub-report in the details section but that created a duplicate record issue if there was more than one record for Job.Job that satisfied my selection. So to fix that I created a group for Job.Job, and put the sub-report in the group header and suppressed the detail.
I'm not sure this is the most efficient use of CPU power or the best way to program this in CR, but it gives me the correct results that I need, and relatively quickly for the size of the database.

Your Record Selection forumula should be something like this.
{V_JOB.LMO} = 'L' AND
{V_JOB.JOB}
Now you have all the records in your CR.
Use the below formula as a supression option for the field where you are displaying records.
#Supress
IF {V_JOB.TASK} LIKE "*IN"
AND {V_JOB.CLOSED} = "Y"
AND {V_JOB.DATE} >= {?FrDate}
AND {V_JOB.DATE} <= {?ToDate}
THEN true ELSE false
If your condition is true then all records will be displayed else all records will be supressed.
I would suggest you to not to apply these type of conditions in Record selection formula.

Related

Using checkbox to filter query Access

I'm VERY new to working with Access, and SQL--thank you for your patience with me! I'm working on a query based off of an inventory table:
tblInvnetory:
recordID (PK),
itemID,
setID,
other fields with info specific to item
Not all items have a setID. I would like to have a checkbox on the form with the other search parameters to filter out records that include a setID (e.g. include items from sets). So if box is TRUE = return records with setID. If box is FALSE = return records with no setID.
Would an IIF statement accomplish this? If so, any guidance on what the syntax would look like?
The other thought I've had is to include a checkbox in tblInventory that is "Item is part of Set". So if in the table it is true, and the box on the form is true, it will only return records with a setID. Would I also need an IIF statement for that scenario?
It could be a job for Xor:
Where [Forms]![FormName]![CheckboxName] Xor Not (SetID Is Null)

Access Criteria IIF Statement Issue

I'm trying to qualify a field based on a date. If the frequency of the data is supposed to be weekly, I want to select one specific weekend date. If the frequency is monthly, I want the frequency to include the specific weekend date and all weeks thereafter. However, my statement below returns a blank table when False ("Monthly"). I'm guessing there's some specific formatting I have to do to the >= but I'm drawing a blank. Any suggestions?
=IIf([Frequency]="Weekly",[WK_end_Date],>=[WK_end_Date])
FYI... the false statement works correctly when I input only that specific criteria without the IIF statement.
Thanks,
Mark
You can't use IIf this way. Correct your Where clause like this:
Where
([Frequency] = "Weekly" And [YourDateField] = [WK_end_Date])
Or
([Frequency] <> "Weekly" And [YourDateField] >= [WK_end_Date])

ms Access '16 - Continuous form - OrderBy textbox value created with expression

I have a form that shows the records from Table-A, it is a continuous form. I have a textbox that uses a DCount expression to count records from Table-B that share the same SOP-Number.
=DCount("*","[Table-B]","SOP = " & [SOP])
This works but I don't know how I would go about sorting that column based of the resulting values. The other columns are sorted thus:
" ORDER BY [FIELD NAME] ASC;"
So without a field I don't know how (or if) I can sort the form.
Could I create a RecordSet to store the values then sort by that field (I don't know if this is even possible)
Thank you
Dan
Access 2016 (365)
I'm not quite understanding why you won't know what fields you're pulling from Table B. But you can always order by the column number. So if you're looking to order by the first column, just put:
ORDER BY 1 ASC
You can't sort the recordsource but you can sort the form itself:
Me.OrderBy = "NumTasks DESC"
Me.OrderByOn = True
(assuming your textbox with the DCount control source is named NumTasks ).
You could change the datasource to
select ,DCount('''[Table-B],'SOP=' & SOP) from [Table-A]
order by DCount('*''[Table-B],'SOP=' & SOP)
This is not a good soulution i Table-A is big.

SSRS Expression in field using IN

I am trying to filter the data returned in a field using multi-value parameters. I need to filter based on 3 conditions:
--Before a Warranty End Date
--AND Service Type on the record must match one of the MULTI-VALUE parameters selected by the user
--AND Order Type on the record must match one of the MULTI-VALUE parameters selected by the user
Currently, this works for the first selection I described above (to sum only those records with a service date <= warranty end date , however, I cannot get the syntax to also check the 2 other fields based on the parameters selected...
Sum(iif(Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value, CDbl(Fields!ExtendedCost.Value), CDbl(0)))
Attached is my layout. Eventually I would like initially display everything to the left of % remaining and allow the user to drill down to see the invoice details
warranty
I don't know what is your reason to use parameter to filter the dataset instead of filter your query directly. However this could be what you are looking for.
Try this:
=Sum(iif(
Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value
AND
Join(Parameters!MultiValSTParam.Value,",").Contains(Fields!ServiceType.Value)
AND
Join(Parameters!MultiValOTParam.Value,",").Contains(Fields!OrderType.Value)
,CDbl(Fields!ExtendedCost.Value)
,CDbl(0)
))
EDIT: Edition based on OP comments.
You should use the parameter to filter the query that is generating your dataset at T-SQL level.
Create #WarrantyEDParam (date type), #ServiceType and #OderType parameters, then use them in your query something similar to this.
select
me.equipment_id,
me.WarrantyEndDate,
me.WarrantyReserveAmnt,
so.invoice_id,
so.service_type,
so.order_type,
so.cost,
so.price
from
master_equipment me
left join sales_order so on me.equipment_id = so.equipment_id
where me.WarrantyEndDate <= #WarrantyEDParam
or so.equipment_id is null --This line was added
and so.service_type in (#ServiceTypeParam)
and so.order_type in (#OrderTypeParam)
Now you will get data filtered directly from the query, so to get the sum of ExtendedCost use:
=Sum(CDbl(Fields!ExtendedCost.Value))

Filtering Microsoft Access Subform

I have a subform populated with different tasks. I want to filter them on DUE_DT with a filter that happens automatically. Some of the records have a blank DUE_DT, which I would like to filer out. I would also like to filter out records whose DUE_DT is more than 30 days past. I tried using VB but I haven't been able to find the appropriate syntax.
Here is some syntax for appplying a filter to a sub form:
Forms!MyMainForm.ASubFormOnMyMainForm.Form.Filter = "whatever your filter is"
Forms!MyMainForm.ASubFormOnMyMainForm.Form.FilterOn = True
"I want to filter them on DUE_DT with a filter that happens automatically."
I'm not quite sure what you have in mind there, but I wonder whether that could be handled by a WHERE clause in the subform's record source query.
WHERE DUE_DT >= Date() - 30
That would be automatic in the sense that the filter would always apply.
Note you don't have to add another condition to explicitly exclude Nulls (such as DUE_DT Is Not Null) because Null is not >= Date() - 30.
Try this in VBA, should work on every form or module you put it in:
Form_subFormName.Filter = "DUE_DT IS NOT NULL AND DUE_DT >= #" & (Date - 30) & "#"
Form_subFormName.FilterOn = True
Replace the subFormName in Form_subFormName with the name of your subform, but keep the Form_.