MS Graph API - Combining And/Or into Filter - microsoft-graph-api

I'm trying to use the OData $filter query parameter with the calendarView endpoint in MS Graph. It seems to work fine until I combine AND with OR. Does anyone know the proper syntax?
Private Sub buildQuery()
m_webQuery = "https://graph.microsoft.com/v1.0/me/calendars/calendar/calendarView"
m_webQuery = m_webQuery & "?$select=subject,organizer, start,end"
m_webQuery = m_webQuery & "&startDateTime=" & Format$(m_projectStart, "yyyy-mm-dd")
m_webQuery = m_webQuery & "&endDateTime=" & Format$(m_projectStart + 365, "yyyy-mm-dd")
m_webQuery = m_webQuery & "&$filter= (contains(subject,'PTO') or contains(subject,'OOO')) and organizer/emailAddress/name eq 'John Doe'"
m_webQuery = m_webQuery & "&$orderby=organizer/emailAddress/name"
m_webQuery = m_webQuery & "&$top=500"
End Sub
The filter failing to produce correct results
m_webQuery = m_webQuery & "&$filter= contains(subject,'PTO') or contains(subject,'OOO') and organizer/emailAddress/name eq 'Joe Smith'"
The result should be any event containing PTO or OOO in the subject where the organizer is John Doe
I've tried combining using parans but no avail.

From the testing it's not possible to combine filtering by organizer/emailAddress/name together with filtering by any other property.
So either
m_webQuery = m_webQuery & "&$filter= contains(subject,'PTO') or contains(subject,'OOO')"
or
m_webQuery = m_webQuery & "&$filter=organizer/emailAddress/name eq 'John Doe'"
will work.
Only solution is to use one of the filter above for server side filtering and then apply the other filter on the client.

Related

Using a query with multiple results in a subsequent query - Google Sheets

I have a query that returns 2 or more results.
I want to be able to pass ALL the results, one-by-one to power another query. I decided to embed the queries.
=IFERROR(QUERY('Sheet1'!A1:J36,"SELECT J,B,C,D,E,F,G,H WHERE J Contains '" & B11 & "' AND B='" & QUERY('Sheet2'!$A$3:$AR$103,"SELECT D WHERE " & VLOOKUP($B11,'Test Sheet'!$A$33:$B$43,2,FALSE) & "='Yes' AND (AR='High' OR AR='Low') ORDER BY AH desc" ,0) & "' ORDER BY G desc" ,1),"No Results")
The query as a whole runs successfully, however only the first result of the initial query is passed to the outer query. This means I don't get all the matches I am expecting.
Is there a way of accomplishing this?
I think this is what your'e trying to do, on the MK.Help tab in cell A74.
=IFERROR(QUERY('Interventions V0.2'!A1:J39,"SELECT J,B,C,D,E,F,G,H WHERE J Contains '" & B11 & "' AND B matches'" & JOIN("|",QUERY('Biomarker Ref. Sheet (Static)'!$A$3:$AR$103,"SELECT D WHERE " & VLOOKUP($B11,'Test Sheet'!$A$33:$B$43,2,FALSE) & "='Yes' AND (AR='High' OR AR='Low')",0)) & "' ORDER BY G desc" ,1),"No Results")

Crystal Reports External Join

I have 2 data sources that I am querying, then joining in Crystal Reports on a key string with a Left Outer Join. The intent of the report is to identify purchases made that were not processed. The issue is that CR refuses to show the matching right query records.
Data Source 1: Excel worksheet on my local machine containing raw
credit card purchases. "Left table"
Data Source 2: 2 subqueries from a hosted Oracle database with a
Union join containing processed credit card transactions. "Right
table"
Key String: The last 4 digits of a credit card number concatenated
with the date-time of the transaction, e.g. "223402-06-2019 04:15:00"
The queries return proper values when executed separately. I have verified that many records returned for the Left table actually do have matching Right table records that are not displayed. I did this using a separate report showing only the Right table query results and manually searching for different key strings.
I'm completely buffaloed and any assistance would be appreciated.
The SQL from Crystal Reports:
I:\Dept\DCS\MPOOL\Fleet Management Data\M5\M5 Automation Data Tables\ComData Transaction Data.xls
`SELECT DISTINCT CD.`First Name` AS UNIT_NO,
CD.`HIERARCHY LEVEL3` AS USE_DEPT,
DATEVALUE(MONTH(CD.`Transaction Date`) & "/" & DAY(CD.`Transaction Date`) & "/" & YEAR(CD.`Transaction Date`)) + TIMEVALUE(HOUR(CD.`Transaction Time`) & ":" & MINUTE(CD.`Transaction Time`) & ":" & SECOND(CD.`Transaction Time`)) AS TRANS_DT,
CD.`Odometer` AS ODOMETER,
CD.`Card Number` AS CARD_NO,
RIGHT(CD.`Card Number`, 4) & FORMAT(DATEVALUE(MONTH(CD.`Transaction Date`) & "/" & DAY(CD.`Transaction Date`) & "/" & YEAR(CD.`Transaction Date`)) + TIMEVALUE(HOUR(CD.`Transaction Time`) & ":" & MINUTE(CD.`Transaction Time`) & ":" & SECOND(CD.`Transaction Time`)), "mm-dd-yyyy hh:mm:ss") AS KEYSTRING
FROM `Sheet1$` CD
WHERE ISDATE(CD.`Transaction Date`) AND CD.`Transaction Date` >= FORMAT('02/01/2019', 'mm-dd-yyyy') AND CD.`Transaction Date` <= FORMAT('02/15/2019', 'mm-dd-yyyy')
EXTERNAL JOIN Command.KEYSTRING={?m5oksr: Command_1.KEYSTRING}
m5oksr
SELECT DISTINCT TCC.UNIT_NO,
VUDC.USING_DEPT_NO AS USE_DEPT,
TCC.ISSUE_DT + 2/24 AS TRANS_DT,
TCC.NEW_METER AS ODOMETER,
'COMP' AS STATUS,
TCC.CARD_NO AS CARD_NO,
SUBSTR(TCC.CARD_NO, 16, 4) || TO_CHAR(TCC.ISSUE_DT + 2/24, 'MM-DD-YYYY HH24:MI:SS') AS KEYSTRING,
FROM MFIVE.VIEW_TRIPCARD_COMPLETED_TRANS TCC
LEFT OUTER JOIN VIEW_UNIT_DEPT_COMP VUDC ON TCC.COMPANY = VUDC.COMPANY and TCC.UNIT_NO = VUDC.UNIT_NO
WHERE TCC.ISSUE_DT + 2/24 >= TO_DATE('02/01/2019 00:00:00', 'MM/DD/YYYY HH24:MI:SS') AND TCC.ISSUE_DT + 2/24 <= TO_DATE('02/15/2019 11:59:59', 'MM/DD/YYYY HH24:MI:SS')
UNION
SELECT DISTINCT IR.FIELD2 as UNIT_NO,
VUDC.USING_DEPT_NO AS USE_DEPT,
TO_DATE(IR.FIELD1, 'MM/DD/YYYY HH24:MI:SS') + 2/24 AS TRANS_DT,
IR.METER as ODOMETER,
'FAIL' AS STATUS,
NVL2(IR.FIELD27, CONCAT('XXXX-XXXX-XXXX-', SUBSTR(IR.FIELD27,-4)),'') as CARD_NO,
SUBSTR(NVL2(IR.FIELD27, CONCAT('XXXX-XXXX-XXXX-', SUBSTR(IR.FIELD27,-4)),''), 16, 4) || TO_CHAR(TO_DATE(IR.FIELD1, 'MM/DD/YYYY HH24:MI:SS') + 2/24, 'MM-DD-YYYY HH24:MI:SS') AS KEYSTRING,
FROM INTERFACE_REJECT IR
INNER JOIN INTERFACE_STAT ST ON IR.COMPANY = ST.COMPANY and IR.STAT_ID = ST.STAT_ID
LEFT OUTER JOIN EMP_MAIN E ON IR.COMPANY = E.COMPANY AND IR.FIELD29 = E.TRIPCARD_PIN
LEFT OUTER JOIN VIEW_UNIT_DEPT_COMP VUDC ON IR.COMPANY = VUDC.COMPANY and IR.FIELD2 = VUDC.UNIT_NO
WHERE LENGTH(IR.FIELD1) = 19 AND ST.INTERFACE_NAME = 'M5-TRIP-CARD-INTF' AND TO_DATE(IR.FIELD1, 'MM/DD/YYYY HH24:MI:SS') + 2/24 >=TO_DATE('02/01/2019 00:00:00', 'MM/DD/YYYY HH24:MI:SS') AND TO_DATE(IR.FIELD1, 'MM/DD/YYYY HH24:MI:SS') + 2/24 <= TO_DATE('02/15/2019 11:59:59', 'MM/DD/YYYY HH24:MI:SS')
EXTERNAL JOIN Command_1.KEYSTRING={?I:\Dept\DCS\MPOOL\Fleet Management Data\M5\M5 Automation Data Tables\ComData Transaction Data.xls: Command.KEYSTRING}
Are you sure the join works? If the join doesn't work then you will get nulls and my guess is that this is what is happening. Try to use INNER JOIN instead of Lef join and check if there are any rows returned. If records are returned you may need to cast the values to the same type and trim them. It is possible that the value returned by excel has empty spaces or different value type, which Crystal converts incorrectly

Run query where column = *

Need to run a query on google sheets where the column match any(*) value. I'm doing this because the criteria is filled by refering to another cell (like a filter).
Probably I'm missing something in the syntax.
My last try:
=QUERY(PROD!A:U;"SELECT L, SUM(M), SUM(O), SUM(Q), (1-(SUM(Q)/SUM(O)))
WHERE T = '*' AND D = '*' AND U = '*'
GROUP BY L
ORDER BY SUM(M) DESC
LABEL L 'PRODUTO', SUM(M) 'QUANTIDADE', SUM(Q) 'CUSTO', SUM(O) 'VENDA', (1-(SUM(Q)/SUM(O))) 'MARK-UP'")
Thank you in advance.
In Google Visualization API Query Language (not to be confused with T-SQL, MySQL, etc) the clause WHERE T = '*' means that the content of column T is literally the string *.
To test for a cell being nonempty, use T <> '' (for text columns) or T is not null (for numeric columns).
There are also like and matches for more complex text filtering.

MS Access 07 - wildcard in JOIN query

I've got the following query
SELECT tblUsers.userfullname,
tblReports.reportdate,
tblReports.reportnumber,
tblRawData.reportcategory,
tblRawData.reportissue
FROM tblRawData
RIGHT JOIN (tblUsers RIGHT JOIN tblReports ON tblUsers.userID = tblReports.userID) ON tblReports.reportnumber LIKE "*" & tblRawData.reportnum
WHERE (
((tblUsers.username) Like "*" & [Forms]![frmSelect]![txtUser] & "*")
AND
((tblUsers.userShift) Like "*" & [Forms]![frmSelect]![txtShift] & "*")
);
Which works - except the part of
ON tblReports.reportnumber LIKE "*" & tblRawData.reportnum
what i'm trying to match is instances where
tblReports.reportnumber = 410145
and
tblRawData.reportnum = 12345.410145
or just
tblRawDatw.reportnum = 410145
but for some reason it just will not find that first match (ex: 12345.410145) unless the number is identical like the second match (ex: 410145). I've tried formatting it as a number as well as text - and no luck.
any idea what I may be missing?
Update: I tried making another query with just the two tables and it doesn't like to match. i tried removing the "." (example: 12345.410145 into 12345410145) and no luck. here's my second query.
SELECT tblReports.userID,
tblRawData.reportnum,
tblRawData.reportcategory,
tblRawData.reportissue,
tblReports.reportdate,
tblReports.reportnumber
FROM tblReports
LEFT JOIN tblRawData ON tblReports.reportnumber LIKE "*" & tblRawData.reportnum;
where if the data is like such.
tblReports Report numbers:
410145
410144
410143
410142
410141
and tblRawData report numbers are such:
12345.410145
410143
12344.410141
the resulting query should show me all 5 records from tblReports - but three of those records have the notes and such from tblRawData.
Rewritten to allow for no match.
SELECT
u.userfullname,
r.reportdate,
r.reportnumber,
q.reportcategory,
q.reportissue
FROM (tblusers u
LEFT JOIN tblreports r
ON u.userid = r.userid)
LEFT JOIN (
SELECT
Val(Mid([reportnum],InStr([reportnum],".")+1)) AS RepNo,
r.reportcategory,
r.reportissue
FROM Rawdata AS r) AS q
ON r.reportnumber = q.RepNo
AND q.username Like "*" & [Forms]![frmSelect]![txtUser] & "*"
AND q.userShift Like "*" & [Forms]![frmSelect]![txtShift] & "*"
It is a common enough convention that LEFT JOINs are used rather than RIGHT JOINs.
I didn't check everything, but I have some ideas. Maybe you have to swap the LIKE condition?
tblRawData.reportnum LIKE "*" & tblReports.reportnumber
if that's not the problem, could you try to use the trim function?
Trim(tblReports.reportnumber) LIKE "*" & Trim(tblRawData.reportnum)
The wildcard character for SQL queries is the percent sign '%' not the asterisk. Try using that instead. But if you are including every match then why have that in your query at all?
Access wildcard character reference

ADOQuery Master/Detail

How can I setup a ADOQuery to filter the data to display all lakes that have Brook trout in a DBGrid?
Data:
Nate Pond - LakeMaps.Lake_Name
Brook trout - Species.Species_Name
Creek chub
Golden shiner
Black Pond
Brook trout
Brown bullhead
Common shiner
Lake Placid
Lake trout
Smallmouth bass
Yellow perch
MDB Database
ADoTable1 = LakeMaps MASTER
ADOTable2 = Species DETAIL
Relationship
LakeMaps Table
LakeMaps.Field[0] = Lake_ID: Autonumber --- ]
LakeMaps.Field[1] = Lake_Name: Text--- |
|Relationship set in the access database
Species Table |
Species.Field[0] = Species_ID: numeric --- ]
Species.Field[1] = Species_Name: text
The Species Table is a Detail the LakeMaps is the Master
How can I setup a ADOQuery to filter the data to display all lakes that have Brook trout in a DBGrid?
Filtered Data:
Nate Pond
Brook trout
Creek chub
Golden shiner
Black Pond
Brook trout
Brown bullhead
Common shiner
You can set Filtered = true and then use OnFilterRecord event and check if detail dataset contains requested value (this can be done in loop or with Locate procedure of dataset)
This will probably be very slow on larger amount of data. In those situations I usually filter master records directly in SQL. Something like this:
SELECT * FROM LakeMaps
WHERE Lake_ID in (SELECT Lake_ID
FROM Species INNER JOIN SpeciesLakesRelation
ON (Species.Species_ID = SpeciesLakesRelation.Species_Id)
WHERE SPECIES_NAME = 'Brook Trout')
This SQL returns records from Lakes that have 'Brook Trout'.
SpeciesLakesRelation is table that contains relation between LakeMaps and Species.
Problem with your query in is that text in query must be in apostrophes. If ComboBoxSpecies.Text has value Brook Trout, then SQL evaluates to:
SELECT * FROM LakeMaps WHERE Lake_ID in
(SELECT Lake_ID FROM Species INNER JOIN LakeMaps ON
(Species.Species_ID = LakeMaps.Lake_Id)
WHERE SPECIES_NAME = Brook Trout)
Note that Brook Trout is not in apostrophes, so you get syntax error from MsAccess.
Edit:
As Gerry noted in comment:
apostrophes should be added using QuotedStr function, instead of double apostrophe.
best solution is to use query parameter
Delphi code, using QuotedStr, should look like this:
ADOQuery1.SQL.Add( 'SELECT * FROM LakeMaps WHERE Lake_ID in ' +
'(SELECT Lake_ID FROM Species INNER JOIN LakeMaps ON ' +
'(Species.Species_ID = LakeMaps.Lake_Id) ' +
'WHERE SPECIES_NAME = ' + QuotedStr(ComboBoxSpecies.Text) + ')');
Now, if ComboBoxSpecies.Text has value Brook Trout, then this string:
'WHERE SPECIES_NAME = ' + QuotedStr(ComboBoxSpecies.Text) + ')'
evaluates as:
WHERE SPECIES_NAME = 'Brook Trout')

Resources