Friday, March 23, 2012

Running 2 queries inside third query

Good morning, all.. your mission today (if you accept it) is to
decipher what I am trying to do and offer assistance to the poster.
(me!) I have searched newsgroups but can find no topics similar to my
needs.
Background:
Trying to create a 'dqy' (MS Query) file for distribution to field
personnel. Initial dqy files (when double-clicked) open Excel, connect
to database, and display the data based on the dqy's SQL.
Database structure is:
tblUser.PKID = tblUser_Role.User_ID_FK
tblUser_Role.Role_ID_FK = tblRole.PHID
tblRole_Course.Role_ID_FK = tblRole.PHID
tblRole_Course.Course_ID_FK = tblCourse.PKID
[Don't blame me... I didn't create this!]
Since other user's data requirements are more involved, I created an
Access database that has tables corresponding to the actual data
source. I 'develop' my queries in Access, copy the SQL into Notepad,
add appropriate connection information, and save file as ####.dqy.
This procedure has worked until now.
I cannot get the SQL for QueryA to work when copied into the dqy file.
QueryA works fine in Access!!! QueryA is composed of
qryUserAndTheirRoles and qryRolesAndTheirCourses.
Here is SQL for QueryA:
SELECT DISTINCTROW qryUserAndTheirRoles.PKID,
qryUserAndTheirRoles.Name, qryUserAndTheirRoles.LastName,
qryUserAndTheirRoles.Agency_ID_FK, qryRolesAndTheirCourses.Name
FROM qryUserAndTheirRoles INNER JOIN qryRolesAndTheirCourses ON
qryUserAndTheirRoles.Role_ID_FK = qryRolesAndTheirCourses.Role_ID_FK
SQL for qryUserAndTheirRoles:
SELECT tblUser.PKID, tblUser.Name, tblUser.LastName,
tblUser.Agency_ID_FK, tblUser_Role.Role_ID_FK
FROM tblUser LEFT JOIN tblUser_Role ON tblUser.PKID =
tblUser_Role.User_ID_FK
WHERE (((tblUser.Agency_ID_FK)=13))
SQL for qryRolesAndTheirCourses:
SELECT tblRole_Course.Role_ID_FK, tblCourse.Name
FROM tblCourse LEFT JOIN tblRole_Course ON tblCourse.PKID =
tblRole_Course.Course_ID_FK
I have been unable to find ANY reference source that describes usage
and syntax. Therefore, I have tried MANY combinations of syntax and
structure. None worked. Is there anyone in this esteemed group who
can modify QueryA -- replacing references to the other queries with
working SQL -- so that the code works when placed in a dqy file'
I bow to your expertise... and await salvation! Thanks
gary b
sfrvn AT earthlink.net<sfrvn@.earthlink.net> wrote in message
news:1133362941.170208.75080@.o13g2000cwo.googlegroups.com...
> Good morning, all.. your mission today (if you accept it) ...
I'm still waiting for this message to auto-destruct.sql

No comments:

Post a Comment