Results 1 to 7 of 7
  1. #1
    Benjamin Breeg is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    4

    Chronological Query/Report

    I would like to create a report/query that displays a "date" field from two or more columns of a table into one column on a report (sorting ascending):

    I´ve this:
    NAME DATE1 DATE2 DATE3
    Name1 23-02-2011 30-02-2011 03-03-2011
    Name2 01-01-2011 30-02-2011 02-02-2011


    Name3 02-01-2011


    Want this:
    Name2 01-01-2011
    Name3 02-01-2011
    Name2 02-02-2011
    Name1 23-02-2011
    Name1 30-02-2011
    Name2 30-02-2011
    Name1 03-03-2011

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why is data in this structure?

    One way is with UNION query. There is no wizard or designer for UNION must type in the SQL View editor of the query designer. Try:

    SELECT [Name], [Date] FROM
    (SELECT [Name], Date1 As [Date] FROM tablename
    UNION SELECT [Name], Date2 FROM tablename
    UNION SELECT [Name], Date3 FROM tablename) As Q1 ORDER BY [Date];
    Last edited by June7; 09-10-2011 at 02:17 AM.
    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
    Benjamin Breeg is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    4

    Thumbs up

    Great!
    It solved the problem. Thanks a lot.

    By the way, what do you mean by "Why is data in this structure?"
    Do you think it could be otherwise?
    The reason it's in that structure is because it calculate a new date from other, Exmp. Date2=Date1+30..., and because those dates are time limits for me to do something, and when passed, i often need that info to be close my main form.
    Do you think i could do with another table structure?
    Thanks in advanced.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Having similar name fields of same data type is an indicator that structure is not proper, hence having to resort to UNION query, which has issues I won't get into. The result of the UNION is conventional structure for data.

    Also, a principle of relational database is 'save raw data, do calcs in report'. Since Date2 is calculated with a constant of 30, this date can always be calculated as needed. Are you using the Calculated datatype field? If so, then the date is being calculated 'on the fly' and is not actually a static value.

    So the next question is: Why do you need to rearrange the data?

    Those dates are in dd/mm/yyyy form instead Access convention of mm/dd/yyyy. Does this cause you issues when calculating?
    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.

  5. #5
    Benjamin Breeg is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    4

    Exclamation

    Quote Originally Posted by June7 View Post
    Having similar name fields of same data type is an indicator that structure is not proper, hence having to resort to UNION query, which has issues I won't get into. The result of the UNION is conventional structure for data.

    Also, a principle of relational database is 'save raw data, do calcs in report'. Since Date2 is calculated with a constant of 30, this date can always be calculated as needed. Are you using the Calculated datatype field? If so, then the date is being calculated 'on the fly' and is not actually a static value.

    So the next question is: Why do you need to rearrange the data?

    Those dates are in dd/mm/yyyy form instead Access convention of mm/dd/yyyy. Does this cause you issues when calculating?
    I accept that principle, but i want do visualize the calculated date field in my form, so i can pass through records and have the value calculated.

    I'm from Portugal and the way we display date is dd/mm/yyyy or yyyy/mm/dd, so it's for easy of comprehension. (I believe that there is no issue with calculate.)

    Meanwhile, i've just realized that i did not got the question right.
    Because i also want to see in that query, the column of the date field name, so i can correspond to the displayed date (my bad)

    like this:

    Name2 01-01-2011 Date1
    Name3 02-01-2011 Date1
    Name2 02-02-2011 Date3
    Name1 23-02-2011 Date1
    Name1 30-02-2011 Date2
    Name2 30-02-2011 Date2
    Name1 03-03-2011 Date3

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Then:
    SELECT * FROM
    (SELECT [Name], Date1 As [Date], "Date1" As Source FROM tablename
    UNION SELECT [Name], Date2, "Date2" FROM tablename
    UNION SELECT [Name], Date3, "Date3" FROM tablename) As Q1 ORDER BY [Date];
    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.

  7. #7
    Benjamin Breeg is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    4
    It solved the problem.

    Thanks!

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

Similar Threads

  1. Replies: 1
    Last Post: 07-15-2011, 10:59 PM
  2. Query for Report
    By Luis Ferreira in forum Queries
    Replies: 6
    Last Post: 10-25-2010, 10:41 AM
  3. Report based on query + sub-report (1:N relation)
    By BayerMeister in forum Reports
    Replies: 1
    Last Post: 08-19-2010, 03:26 AM
  4. Replies: 3
    Last Post: 05-21-2010, 03:57 PM
  5. Replies: 1
    Last Post: 02-02-2009, 05:52 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