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")
Related
In Column A I have the id of the home team, B the name of the home team, C the id of the visiting team and in D the name of the visiting team:
12345 Borac Banja Luka 98765 B36
678910 Panevezys 43214 Milsami
1112131415 Flora 7852564 SJK
1617181920 Magpies 874236551 Dila
I want to create a column of ids and another of names but keeping the sequence of who will play with whom:
12345 Borac Banja Luka
98765 B36
678910 Panevezys
43214 Milsami
1112131415 Flora
7852564 SJK
1617181920 Magpies
874236551 Dila
Currently (the model works) I'm joining the columns with a special character, using flatten and finally split:
=ARRAYFORMULA(SPLIT(FLATTEN({
FILTER(A1:A&"§§§§§"&B1:B,(A1:A<>"")*(B1:B<>"")),
FILTER(C1:C&"§§§§§"&D1:D,(C1:C<>"")*(D1:D<>""))
}),"§§§§§"))
Is there a less archaic and correct approach to working in this type of case?
Spreadsheet to tests
889
A
5687
C
532
B
8723
D
Stack up the columns using {} and SORT them by a SEQUENCE of 1,2,1,2:
=SORT({A1:B2;C1:D2},{SEQUENCE(ROWS(A1:B2));SEQUENCE(ROWS(A1:B2))},1)
889
A
5687
C
532
B
8723
D
You can also try with function QUERY, enter this formula in F1:
={QUERY((A1:B), "SELECT * WHERE A IS NOT NULL and B IS NOT NULL",1);
QUERY((C1:D), "SELECT * WHERE C IS NOT NULL and D IS NOT NULL",1)}
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
I have a form and a list box what is filter with the criteria when the user is selecting from Combo Boxes.
And the record source from the list box is a query so i want to filter the query
I have used this code in query designer
Like " * " & [Forms]![Costumers]![PB_City] & " * " in order to get partial text from the table
but it don't show a record if the field is blank.
The code Like " * " & [Forms]![AnyForm]![AnyThing] & " * " leave out the Blank records
as I like to use the query designer
I wonder what's the exact syntax for the SQL or how to work in the query designer
to get this work done as well
I found a code whats work type in query designer the following:
if you want to write in SQL take a look on this question,
Click on this link
https://stackoverflow.com/a/38899574/9661307
or https://stackoverflow.com/a/38852152/9661307
in Query designer do the following
under your column you do the criteria
Like "*" & [Forms]![myForm]![myControl] & "*" OR [Forms]![myForm]![myControl] Is
Null
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.
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