MS Access Form to add "And Or" operator in SQL Query - ms-access-2013

Summary: I've got a MS Access 2013 database containing information on employee transcripts, and currently configuring a form to let our educators create queries without needing to get technical in SQL or learn MS Access (i.e. text fields and drop downs). So far I have a few text box fields which work and allow them to search specific columns for information entered.
What I'd like to do: is add in a drop down that will add the "And" "Or" operator between fields. I'm having trouble figuring out the SQL syntax in the query to function.
Here is the current code: Training Title and Transcript Date are the two user input text boxes and Criteria 1 is the dropdown I have in the form to choose And Or
However, I'm getting syntax erros when I try to save it.
MS Access Form
WHERE (((User.[RN Residency]) =Forms!QBF_Form![RN Residency] Or Forms!QBF_Form![RN Residency] Is Null)
AND
(((Training.[Training Title]) Like "*"&Forms!QBF_Form![Training Title]& "*" Or Forms!QBF_Form![Training Title] Is Null)
(Forms!QBF_Form![Criteria 1])
((Training.[Transcript Date]) Like "*"&Forms!QBF_Form![Transcript Date]&"*" Or Forms!QBF_Form![Transcript Date] Is Null))```

First, you may have to specify the data type for the parameters.
Next, correct syntax
Finally, it could be:
PARAMETERS
Forms!QBF_Form![RN Residency] Text,
Forms!QBF_Form![Training Title] Text,
Forms!QBF_Form![Transcript Date] DateTime;
<snip>
WHERE
((User.[RN Residency] = Forms!QBF_Form![RN Residency] Or Forms!QBF_Form![RN Residency] Is Null)
AND
(Training.[Training Title] Like "*" & Forms!QBF_Form![Training Title] & "*" Or Forms!QBF_Form![Training Title] Is Null)
AND
(Training.[Transcript Date] = Forms!QBF_Form![Transcript Date] Or Forms!QBF_Form![Transcript Date] Is Null))

Related

Netsuite Saved Search Criteria Formula with 2 fields

I'm trying to do a saved search filter with a formula (text) criteria based on 2 fields, an item field and custom field.
How can I write the correct formula text in criteria? to create the correct filter to find a specific word in this 2 fields
Eg: I have items called with special nomenclature (SERIAL NUMBER_CODE) and also I created a custom field into journal entry line called (SERIAL NUMBER_CODE_RELATED not an item) now I need to find in the saved search all type of transaction with a specific SERIAL NUMBER_CODE + journal entry that have that SERIAL CODE as well into the line, also add a filter that a user can type the SERIAL CODE and bring transactions + journals.
I used this formula (text) in criteria:
CASE WHEN {custom_field} = 'SERIALCODE' OR {item} = 'SERIALCODE' THEN '1' ELSE '0' END
IS = space
Type = all kind of netsuite transaction
in available filter tap I added formula text show in filter region
the result doesn't bring me anything
Thank you
Try
formulatext NVL({custom_field},{item}) is %
Or
formulatext {custom_field}||' '||{item} contains space

Filter Recent date in filter

I want the Slicer in Power BI to select the most recent date of the selection to be selected automatically.
Here is an example of the drop down:
https://i.imgur.com/IykHSlI.png
This drop down differs from the Client selection.
I solved this issue the following way:
I created one Report with a filter to Default_Date (which opens first)
I used a Calculated Column [Default_Date] to populate the filter (which is hidden)
In my case the user wanted to see Yesterday's data as the default date so I selected 'Yesterday' on my filter.
Then I put a button that opens another duplicated copy of the Report [Hidden Tab] that contains a full calendar filter, so the user can select any other dates he likes, this hidden report has another button that returns the user to the main report [if he wants to].
picture of my filter (which I collapse and hide under a color box/banner)
Here is the formula for the calculated column (used in the filter):
Default_Date =
VAR TodaysDate =
TODAY()
VAR YesterdayDate =
TODAY() - 1
VAR reportDate =
SWITCH(TRUE(),
'Calendar'[Date] = TodaysDate, "Today",
'Calendar'[Date] = YesterdayDate, "Yesterday",
"Before Yesterday"
)
RETURN
reportDate
Use Default_Date in your filter, and you can replace TODAY() with
CALCULATE(Max(Table[Date]),All(Table))
and remove what you don't need.
If you want to get the Last Date of selected items, then
CALCULATE(Max(Table[Date]),ALLSELECTED(Table))
Table may need to be in quotes to work: 'Table'[Date]
I hope this helps.
There isn't to set a default value in Power BI, but there are a few around about ways. First you can try Persistent Filters that can preserve the filters selected. The other option, is to create in your data set, if you have a calendar table, or are able to add it to your column a current date flag, that you can apply as a filter to your report.
For example you can use the TODAY() to return todays date, and check against your date column.
Calculated column = IF(MONTH(TODAY()) = MONTH('table'[DateColumn]) && YEAR(TODAY()) = YEAR('table'[DateColumn]), "Y", "N")
You can run the report and it will always filter on the latest date, however you will have to remove the filter if you want to see other dates. You could set up bookmarks so that you can easily add/remove filter to the report. So you would have one bookmark with latest date, and the other to remove it. You can allow the slicer box to appear when you select the 'remove current month' bookmark
Hope that helps

How do I modify a SELECT query to force specific values to be returned for a column, without updating what's actually stored in the table?

I don't know if this is possible, but hopefully this is pretty simply to answer.
Lets say you have read only access to a database (Oracle 11g in this case). You are querying data into an Excel sheet. Part of the data I'm gathering is a panel_name. And I'm only concerned about the data when panel_id=1 OR panel_id=2 OR panel_id=3.
Now, the problem is that for the purposes of this particular query I want to treat panel_id 1 and 3 as if they were the same, not updating the DB, just in the report. So Instead of;
when panel_id=1 then panel_name="Panel 1"
when Panel_id=3 then panel_name="Panel 3"
I'd like override it so that;
when panel_id=1 then panel_name="Panel 1"
when panel_id=3 then panel_name="Panel 1"
I haven't found anything that would allow me to do this though. I'm open to other alternatives as well, but in the end I'd just like to have both of those panels be treated as if they were the same. The code looks something like this;
SELECT
requisitions.received_date AS "Received Date"
,panels.PANEL_NAME AS "Panel Name"
FROM requisitions
inner join panels ON requisitions.PANEL_ID = panels.PANEL_ID
WHERE (panels.PANEL_ID = 1 OR panels.PANEL_ID = 2 OR panels.PANEL_ID = 3)
ORDER BY requisitions.RECEIVED_DATE DESC
Do you just want to have a CASE statement in your query?
SELECT
requisitions.received_date AS "Received Date"
,(CASE WHEN panels.panel_id IN (1,3)
THEN 'Panel 1'
ELSE panels.PANEL_NAME
END) AS "Panel Name"
If that is not what you're asking, it would be very helpful to post some sample data and the expected output of your query.

Conditional Query or Model in Cognos Reporting

I'm new to Cognos Reporting and I'm wondering there is a way to create models/queries that are conditional. For example:
"if x is not null then append this 'where line' to query"
Something like that, I'm still pretty new to Cognos so I may be using the wrong words.
Please help me out.
Thanks.
If you want to filter rows of a query subject,
Right click your query subject> Edit Defition> Filters Tab > Add a filter
In the expression definition box,
x is null or (x is not null and <where expression to append>)
If you want to apply the filter for a query item
case
when x is not null and <where expression to append>
then <some_query_item>
else <some_query_item>
end

set filter to - INLIST - Visual Foxpro 7

I am working on some legacy code, and I have the following wonderful issue. I am hoping some FoxPro experts can help!
The infrastructure of this legacy system is setup so that I have to use the built-in expression engine to return a result set, so no go on the SQL (i know that would be so much easier!)
Here is the issue.
I need to be able to do something like
PUBLIC ARRAY(20) ArrayOfValuesToFilterBy
SELECT dataTable
SET FILTER TO logicalField = .T. and otherField NOT INLIST(ArrayOfValuesToFilterBy)
However, I know this wont work, I just need the equivalency...not using SQL.
I can generate the list of values to filter by via SQL, just not the final record select due to the legacy infrastructure constraint.
Thanks!
First, a logical field you do not have to do explicit
set filter to Logicalfield = .t.
you can just do
set filter to LogicalField
or
set filter to NOT LogicalField
Next, on the array. VFP has a function ASCAN() which will scan an array for a value, if found, will return the row number within the array that matches what you are looking for.
As for arrays... ex:
DIMENSION MyArray[3]
MyArray[1] = "test1"
MyArray[2] = "something"
MyArray[3] = "anything else"
? ASCAN( MyArray, "else" ) && this will return 0
? ASCAN( MyArray, "anything else" ) && this will return 3
If you are doing a "set filter", the array needs to be "in scope" for the duration of the filter. If you set filter in a procedure the array exists, leave the procedure and the array is gone, you're done.
So, you could do
set filter to LogicalField and ASCAN( YourArray, StringColumnFromTable ) > 0
Now, if you want a subset to WORK WITH, you can do a SQL-Select and pull the data into a CURSOR (temporary read-write table) that has the same capabilities of the original table (except auto-increment when adding)...
I typically name my temporary cursors prefixed with "C_" for "CURSOR OF" so when I'm working with tables, I know if its production data, or just available for temp purposes for quicker display, presentation, extractions from other origins as needed.
use in select( "C_FinalRecords" )
select * from YourTable ;
where LogicalField ;
and ASCAN( YourArray, StringColumnFromTable ) > 0;
into cursor C_FinalRecords READWRITE
Then, you can just use that...
select C_FinalRecords
scan
do something with the record, or values of it...
endscan
or.. bind to a grid in a form, etc...
The INLIST() function takes an expression to search for and up to 24 expressions of the same data type to search.
SELECT dataTable
SET FILTER TO logicalField = .T. AND NOT INLIST(otherField, 'Value1', 'Value2', 'Value3', 'Value4')
I am making some assumptions here, that what you want to do is create a filter with a dynamic in list statement ? If this is correct have a play with this example :-
lcList1="ABCD"
lcList2="EFGH"
lcList3="IJKL"
lcList4="MNOP"
lcList5="QRST"
lcFullList=""
lcFullList=lcFullList+"'"+lcList1+"',"
lcFullList=lcFullList+"'"+lcList2+"',"
lcFullList=lcFullList+"'"+lcList3+"',"
lcFullList=lcFullList+"'"+lcList4+"',"
lcFullList=lcFullList+"'"+lcList5+"'"
lcField="PCode"
lcFilter="SET FILTER TO INLIST ("+lcField+","+lcFullList+")"
The results of the above would create the following filter statement and store it in lcFilter
SET FILTER TO INLIST (PCode,'ABCD','EFGH','IJKL','MNOP','QRST')
you can then use macro substitution
Select dataTable
&lcFilter
Bear in mind that there is likely to be some limitations on how many items you can define in a INLIST() statement

Resources