Results 1 to 3 of 3
  1. #1
    ruthib4 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    29

    Red face Substracting months to a date


    Hi Everybody,
    I need your help is possible, i have the following query, qhet I need to get from it is the ifnormation of my DB of the last 13 months.

    SELECT [Recoveries TC].Fecha, [Recoveries TC].País, Sum([Recoveries TC].[Debit TC]) AS [SumaDeDebit TC], Sum([Recoveries TC].[Credit Tc]) AS [SumaDeCredit Tc], Sum([Recoveries TC].[Total TC]) AS [SumaDeTotal TC], Sum([GFl TC].[Debit TC]) AS [SumaDeDebit TC1], Sum([GFl TC].[Credit TC]) AS [SumaDeCredit TC1], Sum([GFl TC].[Total TC]) AS [SumaDeTotal TC1], IIf([GFl TC]![Debit TC]=0,0,[Recoveries TC]![Debit TC]/[GFl TC]![Debit TC]) AS RecRatioDeb, IIf([GFl TC]![Credit TC]=0,0,[Recoveries TC]![Credit TC]/[GFl TC]![Credit TC]) AS RecRatioCre, IIf([GFl TC]![total TC]=0,0,[Recoveries TC]![total TC]/[GFl TC]![total TC]) AS RecRatiotot
    FROM [Recoveries TC] LEFT JOIN [GFl TC] ON ([Recoveries TC].Fecha = [GFl TC].Fecha) AND ([Recoveries TC].País = [GFl TC].País)
    WHERE ((([Recoveries TC].Fecha) Between DateAdd("m",-13,Now()) And Now()))
    GROUP BY [Recoveries TC].Fecha, [Recoveries TC].País, IIf([GFl TC]![Debit TC]=0,0,[Recoveries TC]![Debit TC]/[GFl TC]![Debit TC]), IIf([GFl TC]![Credit TC]=0,0,[Recoveries TC]![Credit TC]/[GFl TC]![Credit TC]), IIf([GFl TC]![total TC]=0,0,[Recoveries TC]![total TC]/[GFl TC]![total TC])
    HAVING ((([Recoveries TC].País)=[Formularios]![Dashboard]![cmdPaisKPI]));

    This query qithout the date criteria works perfectly, but when i run with the adddate function i am getting no values, and i am sure there are.

    Please help

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I would break this up into 2 queries. Use a simple SELECT query that pulls the data based on the date criteria you specify.

    Then create a second query based on the first one. Use the second query to do your grouping and summing.

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    1. is Fecha really a Date/Time field or stored as Text?

    2. When using dates, without time, don't use NOW() use DATE() instead.

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

Similar Threads

  1. Replies: 1
    Last Post: 11-12-2010, 01:16 AM
  2. Replies: 11
    Last Post: 08-04-2010, 04:26 PM
  3. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  4. Query criteria, add 5 months to date
    By thart21 in forum Queries
    Replies: 1
    Last Post: 03-29-2010, 05:09 PM
  5. How to show all months
    By Brian62 in forum Queries
    Replies: 4
    Last Post: 10-20-2009, 08:55 AM

Tags for this Thread

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