Hello:
I am using Access 2013.
I have two queries, one that works and one that does not.
This one works...
Code:
SELECT qryFindOps.* FROM ( SELECT DISTINCT dbo_labordtl.opcode FROM dbo_jobhead LEFT JOIN dbo_labordtl ON dbo_jobhead.jobnum = dbo_labordtl.jobnum WHERE dbo_labordtl.jcdept="MA" AND (Left(dbo_jobhead.jobnum,5) = "36800" Or Left(dbo_jobhead.jobnum,5) = "36801" Or Left(dbo_jobhead.jobnum,5) = "36802" Or Left(dbo_jobhead.jobnum,5) = "36803" Or Left(dbo_jobhead.jobnum,5) = "36804") UNION SELECT DISTINCT dbo_Qantellabordtl.opcode FROM dbo_QantelJobHead LEFT JOIN dbo_QantelLaborDtl ON dbo_QantelJobHead.jobnum = dbo_QantelLaborDtl.jobnum WHERE dbo_QantelLaborDtl.jcdept="MA" AND (Left(dbo_QantelJobHead.jobnum,5) = "36800" Or Left(dbo_QantelJobHead.jobnum,5) = "36801" Or Left(dbo_QantelJobHead.jobnum,5) = "36802" Or Left(dbo_QantelJobHead.jobnum,5) = "36803" Or Left(dbo_QantelJobHead.jobnum,5) = "36804")) as qryFindOps ORDER BY qryFindOps.opcode
This one fails...
Code:
SELECT qryFindOps.* FROM ( SELECT DISTINCT dbo_labordtl.opcode FROM dbo_jobhead LEFT JOIN dbo_labordtl ON dbo_jobhead.jobnum = dbo_labordtl.jobnum WHERE dbo_labordtl.jcdept="MA" AND dbo_labordtl.opcode LIKE '1???' AND (Left(dbo_jobhead.jobnum,5) = "36800" Or Left(dbo_jobhead.jobnum,5) = "36801" Or Left(dbo_jobhead.jobnum,5) = "36802" Or Left(dbo_jobhead.jobnum,5) = "36803" Or Left(dbo_jobhead.jobnum,5) = "36804") UNION SELECT DISTINCT dbo_Qantellabordtl.opcode FROM dbo_QantelJobHead LEFT JOIN dbo_QantelLaborDtl ON dbo_QantelJobHead.jobnum = dbo_QantelLaborDtl.jobnum WHERE dbo_QantelLaborDtl.jcdept="MA" AND dbo_labordtl.opcode LIKE '1???' AND (Left(dbo_jobhead.jobnum,5) = "36800" Or Left(dbo_jobhead.jobnum,5) = "36801" Or Left(dbo_jobhead.jobnum,5) = "36802" Or Left(dbo_jobhead.jobnum,5) = "36803" Or Left(dbo_jobhead.jobnum,5) = "36804")) as qryFindOps ORDER BY qryFindOps.opcode
The query returns a distinct group of four digit string numbers, such as '0007', '0020', '0060', ..., '1000', '1100'. My goal is to only include numbers that start with a 1, so that in the above example only the last two would be considered. I was hoping changing
Code:
WHERE dbo_QantelLaborDtl.jcdept="MA"
to
Code:
WHERE dbo_QantelLaborDtl.jcdept="MA" AND dbo_labordtl.opcode LIKE '1???'
would have narrowed my list. Instead I have ther query asking me for more information. It is looking for the dbo_labordtl.opcode.
I am guessing something needs to change in the fields selected in the initial SELECT DISTINCT portion of the query.
Code:
SELECT DISTINCT dbo_labordtl.opcode FROM
as if it does not weant to select itself or something.
The other query in the statement, qryFindOps, I believe is being created with the statement as some kind of alias. This as well, I do not really understand, if you have any reference you can point me to to help. The point here is, there is no query saved that is being accessed in the database with this name.
Any light you can shed would be much appreciated.
Thanks,