Results 1 to 11 of 11
  1. #1
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27

    Does Access Allow a single query that pulls sections of the same data?

    Hi All,


    I am trying to run a query that pulls sections from a list of data (post-reccesion moves in the S&P500)

    Here is what the query looks like, but access doesnt return anything - I wonder if it is possible?

    Many thanks for any help!

    Code:
    SELECT tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST
    FROM tbl_SP_500
    WHERE (((tbl_SP_500.Period) Between #2/1/1961# And #2/1/1965#) AND ((tbl_SP_500.Period) Between #11/1/1970# And #11/1/1974#) AND ((tbl_SP_500.Period) Between #3/1/1975# And #3/1/1975#) AND ((tbl_SP_500.Period) Between #11/1/1982# And #11/1/1986#) AND ((tbl_SP_500.Period) Between #3/1/1991# And #3/1/1995#) AND ((tbl_SP_500.Period) Between #11/1/2001# And #11/1/2004#) AND ((tbl_SP_500.Period) Between #1/1/2009# And #1/1/2012#));

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Perhaps you wanted "OR" instead of "AND"? A date can't be in the 60's and in the 70's and...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Thanks pbaldy

    I tried it like this, but found that access is not registering the differnet data ranges, and instead gives me the same values of dates and prices 7x, instead of 7 different time series from the same data

    Code:
    SELECT tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST
    FROM tbl_SP_500
    WHERE (((tbl_SP_500.Period) Between #2/1/1961# and #2/1/1965#) or ((tbl_SP_500.Period) Between #11/1/1970# and #11/1/1974#) or ((tbl_SP_500.Period) Between #3/1/1975# and #3/1/1975#) or ((tbl_SP_500.Period) Between #11/1/1982# and #11/1/1986#) or ((tbl_SP_500.Period) Between #3/1/1991# And #3/1/1995#) or((tbl_SP_500.Period) Between #11/1/2001# And #11/1/2004#) or ((tbl_SP_500.Period) Between #1/1/2009# And #1/1/2012#));

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Just curious -- why do you repeat the fields?

    SELECT tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST,


    How is tbl_SP_500.Period defined? What values?

  5. #5
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Quote Originally Posted by orange View Post
    Just curious -- why do you repeat the fields?

    SELECT tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST,


    How is tbl_SP_500.Period defined? What values?
    that is defined as date, Orange - i have a series from 1950 to current, and all i want to do is extract time periods when recssions ended and the corresponding price (px_last)

    i.e. :

    February 1961
    November 1970
    March 1975
    November 1982
    March 1991
    November 2001
    June 2009

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Can you post the db, or a representative sample, and the result you're trying to get?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Sure, the database was too large, here is the excel format and the query (that doesnt work):

    sample sp500 8.20.12.zip

    Code:
    SELECT tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST, tbl_SP_500.Period, tbl_SP_500.PX_LAST
    FROM tbl_SP_500
    WHERE (((tbl_SP_500.Period) Between #2/1/1961# and #2/1/1965#) or ((tbl_SP_500.Period) Between #11/1/1970# and #11/1/1974#) or ((tbl_SP_500.Period) Between #3/1/1975# and #3/1/1975#) or ((tbl_SP_500.Period) Between #11/1/1982# and #11/1/1986#) or ((tbl_SP_500.Period) Between #3/1/1991# And #3/1/1995#) or((tbl_SP_500.Period) Between #11/1/2001# And #11/1/2004#) or ((tbl_SP_500.Period) Between #1/1/2009# And #1/1/2012#));
    All help is appreciated!

    thanks!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Well, I would say the query works in that it returns what you've asked it to. Can you can draw a picture of what you expect?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    Click image for larger version. 

Name:	SP Sample Pic.PNG 
Views:	5 
Size:	43.3 KB 
ID:	8884

    yes, like this - but for some reason, my access query keeps giving me the same thing over/over again

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Like I said, it's giving you what you asked for: records whose dates fall within those periods of time. Structuring it like you want is a whole 'nother matter. Offhand I don't think you're going to get a query to return records like that, or not easily anyway. The best way I can think of is separate queries for each date range, with each feeding a subreport on a main report, stacked side-by-side.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    mrr2 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    27
    thank you pbaldy - I appreciate you looking into this for me.

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

Similar Threads

  1. Form pulls totals from query
    By seth.murphine in forum Forms
    Replies: 3
    Last Post: 04-17-2012, 08:23 AM
  2. Replies: 7
    Last Post: 03-14-2012, 10:56 AM
  3. Exporting single query and single report.
    By rfhall50 in forum Programming
    Replies: 2
    Last Post: 02-18-2011, 12:08 PM
  4. Replies: 7
    Last Post: 11-13-2010, 08:08 AM
  5. Replies: 1
    Last Post: 02-13-2010, 12:44 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