Results 1 to 4 of 4
  1. #1
    eugzl is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    68

    how convert SQL select with subquery to Access query

    Hi All.
    How to convert this Select statement to Access query


    Code:
    select
    RequestID
    , RequestDate
    , Department
    , FirstName
    , LastName
    , TicketNo
    , Amount
    , DeviceType &' '& Brand & ' '& Model as Device
    , Facility & ' ' & Building & ' ' & Wing & cast(Floor as varchar(10)) & '-' & Room as Location
    from tblRequests r
    left join (
                select
                DeviceID
                , DeviceType
                , Brand
                , Model
                from tblDevices d
                left join tblBrands b
                on d.BrandID=b.BrandID
                left join tblDeviceTypes dt
                on d.DeviceTypeID=dt.DeviceTypeID
                left join tblModels m
                on d.ModelID=m.ModelID) as d
    on r.DeviceID=d.DeviceID
    left join (
                select
                LocationID
                , Facility
                , Building
                , Wing
                , Floor
                , Room
                from tblLocations l
                left join tblFacilities fa
                on l.FacilityID=fa.FacilityID
                left join tblBuildings b
                on l.BuildingID=b.BuildingID
                left join tblWings w
                on l.WingID=w.WingID
                left join tblFloors fl
                on l.FloorID=fl.FloorID) as l
    on r.LocationID=l.LocationID
    I will appreciate for help. Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Access gets picky about parentheses around JOIN clauses. Suggest you use the query designer to build then view query in SQL view.

    Build the inner SELECT queries independently then copy/paste SQL into outer query to build all-in-one SQL.

    Could provide your db for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    eugzl is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    68
    Hi June7. Thanks for reply.
    If I understood correct I must create in my case three query and then join them. Is it correct?
    Thanks.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Use query builder to get the syntax correct. Inner queries can remain as separate objects that are referenced by outer query or if you want to combine into one SQL then copy/paste. Once it all works correct can delete the query objects.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 06-16-2021, 02:14 AM
  2. Replies: 11
    Last Post: 11-08-2013, 06:14 PM
  3. Replies: 2
    Last Post: 09-26-2013, 09:13 PM
  4. INSERT INTO ... SELECT Subquery
    By TheDeceived in forum Programming
    Replies: 1
    Last Post: 10-19-2010, 09:29 AM
  5. Convert query sql server for Access
    By webtony in forum Queries
    Replies: 0
    Last Post: 06-23-2009, 02:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums