Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 1st, 2007, 09:24 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Complex(?) Count Query Causing Access to Crash

Hey everybody! This is my first post here, so hopefully I will be able to make it as clear as possible. I have a very large database (over 1,000,000 entries) and my current goal is to find out the number of 'sessions' that a person does during his or her lifetime in the database.

I have a table that has records of each person (each have their own unique ID), and the date of that person's visit. I have defined a session as being complete if the person does not come back for a visit in a 3 week period. After the 3 week period, if the person comes back for another visit, a new session is started.

There are thousands of unique persons in the database, and a person will often visit many many times.

My Goal: to determine how many 'sessions' each patient does.

Someone from another site has suggested using this code:

Code:
SELECT x.[Patient ID], Count(x.Date) AS CountOfSessions
FROM Query1 AS x
WHERE (((DateDiff("d",Nz((SELECT TOP 1 Date FROM Query1 WHERE [Patient ID] = x.[Patient ID] AND Date < x.Date ORDER BY Date DESC;),0),[Date]))>21))
GROUP BY x.[Patient ID];
but that Causes Access to crash (I enter it in the SQL code view of a query.

I am using Access 2003 on Windows XP if that helps.

Thank you so much for your time!

-Chris

Reply With Quote
  #2 (permalink)  
Old August 6th, 2007, 11:16 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What is Query1? Do you have the SQL from that query? This query relies a lot on that and so the problem may be with Query1, and not with this query.

I would also suggest moving the WHERE clause to another query.

Can you post the SQL from query1?

mmcdonal
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cr8 & Stored procedure ..Crash ..Crash swissaKM Crystal Reports 0 January 2nd, 2005 06:02 AM
Can't find record, causes Access to crash mmcdonal Access 2 December 3rd, 2004 02:51 PM
query too complex liz@trinityholdings.co.za Access 3 August 28th, 2003 09:01 AM
Refresh causing Query Engine Error Deecay Crystal Reports 0 July 10th, 2003 09:27 PM



All times are GMT -4. The time now is 06:30 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.