Results 1 to 3 of 3
  1. #1
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228

    SQL - Embed Query Into From Statement

    Hello, I'm looking to create a recordset in which I need to embed a query into a second query.

    My first query in the following code is titled "Testing".

    Code:
    SELECT Test.Hours, Sum([Testing].[Claims]*IIf([Confidence].[Confidence] Is Null,1,[Confidence].[Confidence])) AS Claims FROM Testing AS Test LEFT JOIN [Top 10 - Solution Confidence] AS Confidence ON (Test.User = Confidence.Username) AND (Test.[Part Assignment] = Confidence.[Part Assignment]) GROUP BY Test.Hours;
    How do I replace the title of the query with the actual SQL? For instance it would be adjusted to something like the following...



    Code:
    SELECT Test.Hours, Sum([Testing].[Claims]*IIf([Confidence].[Confidence] Is Null,1,[Confidence].[Confidence])) AS Claims FROM 'Insert SQL that defines query Testing here' AS Test LEFT JOIN [Top 10 - Solution Confidence] AS Confidence ON (Test.User = Confidence.Username) AND (Test.[Part Assignment] = Confidence.[Part Assignment]) GROUP BY Test.Hours;
    I've seen this done elsewhere but cannot find reference to it. I've tried brackets, parentheses, quotes, etc. I'm not sure how to structure it.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Instead of

    FROM Testing

    try

    FROM (sql string) AS Test

    And if that does not work, describe what happens - error message, wrong results, nothing? And provide Testing sql statement.
    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
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    I found the error.

    The parentheses does the trick, however you must remove the ; from the end of the embedded sql.

    Code:
    SELECT Test.Hours, Sum([Testing].[Claims]*IIf([Confidence].[Confidence] Is Null,1,[Confidence].[Confidence])) AS Claims FROM (SELECT testTbl.* FROM testTbl) AS Test LEFT JOIN [Top 10 - Solution Confidence] AS Confidence ON (Test.User = Confidence.Username) AND (Test.[Part Assignment] = Confidence.[Part Assignment]) GROUP BY Test.Hours;

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

Similar Threads

  1. embed hyperlink in vba generated email
    By jlawson258 in forum Forms
    Replies: 1
    Last Post: 11-21-2016, 08:11 AM
  2. Embed interactive word document.
    By BatmanMR287 in forum Access
    Replies: 3
    Last Post: 01-26-2015, 01:35 PM
  3. Embed Invoice Print within Statement Print
    By EddieN1 in forum Reports
    Replies: 2
    Last Post: 11-16-2013, 10:38 PM
  4. Embed word document into form
    By jgelpi16 in forum Forms
    Replies: 4
    Last Post: 06-26-2012, 11:31 AM
  5. embed fonts in access2007
    By rbg in forum Access
    Replies: 3
    Last Post: 12-08-2010, 03:29 PM

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