Results 1 to 9 of 9
  1. #1
    bergjes is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2010
    Posts
    8

    How to start?

    Hi,

    hope you can help me with following.

    I have this table with data from a few years (and counting)

    I need a query to select the data from the accountnumbers from the current year and the year before that, so I can calculate the difference between them.

    For now I have 3 years, 2010, 2011 and 2012.
    But in my query only the years 2011 and 2012 shows?


    I need all three years.

    Code:
    SELECT Qry_omzet_week_rek.jaar, Qry_omzet_week_rek.Rekeningnr, Qry_omzet_week_rek.Weeknr, Qry_omzet_week_rek.omzet_week AS [Omzet week bj], Qry_omzet_week_rek_1.omzet_week AS [Omzet week vj]
    FROM Qry_omzet_week_rek _
    INNER JOIN Qry_omzet_week_rek AS Qry_omzet_week_rek_1 _
    ON (Qry_omzet_week_rek.Rekeningnr = Qry_omzet_week_rek_1.Rekeningnr) AND (Qry_omzet_week_rek.Weeknr = Qry_omzet_week_rek_1.Weeknr)
    WHERE (((Qry_omzet_week_rek_1.jaar)=[Qry_omzet_week_rek].[jaar]-1));
    Hope someone can help me?
    Perhaps I'm going all wrong about this, perhaps there is an other way to get the right results?

    Thanks.
    Erik

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    Can't be certain, but it looks like the posted query is based on another query rather than a table. If this is the case, look at the underlying query to see if there is a WHERE clause limiting the years retrieved.

  3. #3
    bergjes is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2010
    Posts
    8
    Thanks,

    you are right, it is based on an other query, but only because I only need a small part of the table data. And there is no WHERE clause in that query.

    Gr,
    Erik

  4. #4
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Two more comments

    Quote Originally Posted by bergjes View Post
    Thanks,

    you are right, it is based on an other query, but only because I only need a small part of the table data. And there is no WHERE clause in that query.

    Gr,
    Erik
    Can you identify the 'year' fields? When I look at the query, I guess that it is dealing with weekly events.
    Having blanks in name and especially field names is not good.

  5. #5
    bergjes is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2010
    Posts
    8
    I'm not sure what you mean by "Can you identify the 'year' fields?"

    Perhaps it would have been better if I made the query in "english"

    year = jaar
    week = Weeknr
    accountnumber = Rekeningnr
    amount = omzet_week

    Hope this is what you mean?

  6. #6
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Your last post confirmed my guesses. However, I'm not following

    what the join between the two tables accomplishes. It is more a matter of my not having any feel for the data and your processes.
    I say again, having blanks in your field names (following AS) is a bad idea. Either compact them or use underscores. However, I don't think that will solve your two years of data vs. three years desired. I'll think about it some more.

  7. #7
    bergjes is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2010
    Posts
    8
    Hi,
    I re-write the query, so perhaps this makes things more clear?

    The tabel has 9 records , but my query only 6 records (the ones from year 2010 are missing)


    Table result
    Code:
          sales    Id year accountnumber weeknumber amount 
         1079 2010 1000 1 1.011,38 
        1084 2010 1000 2 544,35 
        1090 2010 1000 3 557,31     
    1597 2011 1000 1 766,05 
        1603 2011 1000 2 494,35     
    1609 2011 1000 3 507,31     
    2116 2012 1000 1 866,05     
    2122 2012 1000 2 594,35     
    2128 2012 1000 3 607,31
    Query result
    Code:
          weeksales    Year accountnumber weeknumber amount_1 amount_2 
         2011 1000 1 766,05 1.011,38 
        2011 1000 2 494,35 544,35     
    2011 1000 3 507,31 557,31     
    2012 1000 1 866,05 766,05     
    2012 1000 2 594,35 494,35 
        2012 1000 3 607,31 507,31
    Code:
    SELECT sales.Year, sales.accountnumber, sales.weeknumber, sales.amount AS amount_1, sales_1.amount AS amount_2
    FROM sales INNER JOIN sales AS sales_1 ON (sales.weeknumber =  sales_1.weeknumber) AND (sales.accountnumber = sales_1.accountnumber)
    WHERE (([sales_1].[year]=[sales].[year]-1));

  8. #8
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481
    I do queries in the QBE design view so I'm not much in SQL, but here's what I think needs to be changed

    SELECT sales.Year, sales.accountnumber, sales.weeknumber, sales.amount AS amount_1, sales_1.amount AS amount_2, sales_2.amount AS amount_3

    FROM sales INNER JOIN sales AS sales_1 ON (sales.weeknumber = sales_1.weeknumber) AND (sales.accountnumber = sales_1.accountnumber)
    AND (sales.weeknumber = sales_2.weeknumber)

    WHERE (([sales_1].[year]=[sales].[year]-1) AND ([sales_2].[year] = [sales].[year]-2) );

    Good luck.

  9. #9
    bergjes is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2010
    Posts
    8
    Thanks.
    It's much like a pivot table this way.

    Problem Solved

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

Similar Threads

  1. VBA Won't Start
    By Randy in forum Access
    Replies: 3
    Last Post: 11-27-2011, 12:27 PM
  2. Where to start?
    By FullyFamous in forum Database Design
    Replies: 7
    Last Post: 12-20-2010, 03:27 PM
  3. How to start
    By SlowPoke in forum Access
    Replies: 4
    Last Post: 09-16-2010, 07:41 AM
  4. Start
    By LUGO in forum Access
    Replies: 1
    Last Post: 01-30-2010, 11:31 AM
  5. how can i start ?.
    By lavin80 in forum Access
    Replies: 1
    Last Post: 05-23-2009, 11:24 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