Results 1 to 2 of 2
  1. #1
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338

    Combining two queries.

    How can i combine these two queries???

    SELECT T_DocInfo.[Provider Name], [T_Fee Settlement Balance].Month, [T_Fee Settlement Balance].Year, [T_Fee Settlement Balance].[Fee Settlement Balance], [T_Fee Settlement Balance].Refunds, [T_Fee Settlement Balance].[Medical Assoc Transfer], [T_Fee Settlement Balance].[Returned Checks], [T_Fee Settlement Balance].CreditsNotRecordedinClimacsCT, Sum([Fee Settlement Balance]+[Refunds]+[Medical Assoc Transfer]+[Returned Checks]-[CreditsNotRecordedinClimacsCT]) AS [Fee Settlement Sum]
    FROM [T_Fee Settlement Balance] LEFT JOIN T_DocInfo ON [T_Fee Settlement Balance].[Provider Name] = T_DocInfo.ID
    GROUP BY T_DocInfo.[Provider Name], [T_Fee Settlement Balance].Month, [T_Fee Settlement Balance].Year, [T_Fee Settlement Balance].[Fee Settlement Balance], [T_Fee Settlement Balance].Refunds, [T_Fee Settlement Balance].[Medical Assoc Transfer], [T_Fee Settlement Balance].[Returned Checks], [T_Fee Settlement Balance].CreditsNotRecordedinClimacsCT;

    SELECT T_DocInfo.[Provider Name], Format([Date of Posting From],"mmmm") AS [Month], Format([Date of Posting From],"yyyy") AS [Year], Sum([Cash]+[Check]+[Credit Card]) AS Total


    FROM (T_MonthlyTotals INNER JOIN T_MonthlyTotals2 ON T_MonthlyTotals.ID = T_MonthlyTotals2.[ID Main Table]) LEFT JOIN T_DocInfo ON T_MonthlyTotals.[Provider Name] = T_DocInfo.ID
    GROUP BY T_DocInfo.[Provider Name], Format([Date of Posting From],"mmmm"), Format([Date of Posting From],"yyyy"), T_MonthlyTotals2.[Reflected last Month]
    HAVING (((T_MonthlyTotals2.[Reflected last Month])=Yes));

    Thank you

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    Depends on how you want to join them. You can use a union query that will return all records in both queries however the Select clauses in both must A. Contain the same number of fields and b they must be the same type for Example:

    Code:
    Select Month(datefield), Sum(Sales) As Total Sales, "Sales" as type
    From atable
    Union All
    Select Month(datefield, Sum(projectedSales), "Projected" 
    From btable
    A bit simplistic I know but the principle is the same regardless of how many tables and joins there are in the query.

    Secondly If theres a link between query 1 and query 2 just put all of the fields from both in the select and make the appropriate joins in the from. If there is no link combining the 2 queries will give you a cartesian product which means if Query A Returns 10 Records and Query B returns 10 Records the combined query will return 100 Records.

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

Similar Threads

  1. Combining queries..
    By Anthony88 in forum Queries
    Replies: 4
    Last Post: 05-02-2012, 02:46 PM
  2. Combining two queries
    By Adele in forum Queries
    Replies: 1
    Last Post: 07-16-2011, 12:17 AM
  3. combining two queries
    By camell in forum Queries
    Replies: 4
    Last Post: 03-04-2011, 02:41 PM
  4. Combining queries
    By wildlifeaccess in forum Queries
    Replies: 10
    Last Post: 09-20-2010, 07:35 AM
  5. Combining Two Queries
    By csolomon in forum Queries
    Replies: 1
    Last Post: 09-03-2009, 01:33 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