473,659 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Right Join query with Between HELP

1 New Member
Hi,
I have a table with a date_created and date_expired and I want to look
at the 15th of each month and every month since the system started and
count up how many accounts were active at each of those points in
time.
Will have to assume that if there's an expiry date bigger than today
then that account was active at each of those points in time.
I created a numbers table from 1 to 100.
I have the following code working well in SQL2000 but I can't make it work in Access! Can someone tell me how to make this work in Access?

Expand|Select|Wrap|Line Numbers
  1. SELECT The15th, COUNT(Account_Created) AS Cnt 
  2. FROM AccountsHistorical 
  3. RIGHT JOIN (SELECT DATEADD(month,n,'20020703') as The15th FROM Numbers) x 
  4. ON x.The15th BETWEEN AccountsHistorical.Account_Created AND AccountsHistorical.Accounts_Expire 
  5. GROUP BY The15th 
  6. ORDER BY The15th
Mar 20 '07 #1
1 1042
Rabbit
12,516 Recognized Expert Moderator MVP
Hi,
I have a table with a date_created and date_expired and I want to look
at the 15th of each month and every month since the system started and
count up how many accounts were active at each of those points in
time.
Will have to assume that if there's an expiry date bigger than today
then that account was active at each of those points in time.
I created a numbers table from 1 to 100.
I have the following code working well in SQL2000 but I can't make it work in Access! Can someone tell me how to make this work in Access?

Expand|Select|Wrap|Line Numbers
  1. SELECT The15th, COUNT(Account_Created) AS Cnt 
  2. FROM AccountsHistorical 
  3. RIGHT JOIN (SELECT DATEADD(month,n,'20020703') as The15th FROM Numbers) x 
  4. ON x.The15th BETWEEN AccountsHistorical.Account_Created AND AccountsHistorical.Accounts_Expire 
  5. GROUP BY The15th 
  6. ORDER BY The15th
Try:
Expand|Select|Wrap|Line Numbers
  1. SELECT AccountsHistorical.The15th, COUNT(Account_Created) AS Cnt 
  2. FROM AccountsHistorical 
  3. RIGHT JOIN (SELECT DATEADD("m",AccountsHistorical.n,#3/7/2006#) AS The15th FROM Numbers) As x 
  4. ON AccountsHistorical.The15th = x.The15th
  5. GROUP BY AccountsHistorical.The15th
  6. HAVING (AccountsHistorical.The15th BETWEEN AccountsHistorical.Account_Created AND AccountsHistorical.Accounts_Expire)
  7. ORDER BY AccountsHistorical.The15th;
And is n a numeric field in your table?
Mar 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4847
by: Omavlana | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select b.Account_desc, b.Account, a.CSPL_CSPL from Actual_data_final a right outer join Actual_account_Tbl b on a.account_desc = b.account_desc where (a.source_type = 'TY02' or a.source_type is null) and (a.month = '2ND HALF' or a.month is null) and (a.year = 2004 or a.year is null) and (a.product = 'NP' or...
1
1555
by: Omavlana | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select b.Account_desc, b.Account, a.CSPL_CSPL from Actual_data_final a right outer join Actual_account_Tbl b on a.account_desc = b.account_desc where (a.source_type = 'TY02' or a.source_type is null) and (a.month = '2ND HALF' or a.month is null) and (a.year = 2004 or a.year is null) and (a.product = 'NP' or...
4
8167
by: Marek Kotowski | last post by:
Hi, What is the real difference between LEFT JOIN and RIGHT JOIN? Are there situations where a query with RIGHT JOIN cannot be rewritten with LEFT JOIN and tables reversed? (and vice versa). In MySQL documentation there is stated explicitly: "RIGHT JOIN is implemented analogously to LEFT JOIN, with the roles of the tables reversed."
0
1239
by: K k | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select b.Account_desc, b.Account, a.CSPL_CSPL from Actual_data_final a right outer join Actual_account_Tbl b on a.account_desc = b.account_desc where (a.source_type = 'TY02' or a.source_type is null) and (a.month = '2ND HALF' or a.month is null) and (a.year = 2004 or a.year is null) and (a.product = 'NP' or...
5
4040
by: jason.evans | last post by:
Hi there. I am having an intrigueing problem. I have a query which left joins another query to itself twice. The original query is derived from a linked table in SQLServer 2000. When I run it on my pc It runs fine. However for other users in the office, it behaves as an inner join. ie it only returns the records fo which the join fields equal each other. This happens on every other pc
14
5915
by: Jim Andersen | last post by:
I have a problem with this standard employee-supervisor scenario For pictures: http://www.databasedev.co.uk/self-join_query.html I want to show all employees "belonging" to a specific supervisor. E.g, EMP1 and EMP2 both has the same supervisor SUP1. EMP3 has a supervisor SUP2. EMP4 has supervisor SUP3.
0
1050
by: Giorgio | last post by:
Hi, I have a table with a date_created and date_expired and I want to look at the 15th of each month and every month since the system started and count up how many accounts were active at each of those points in time. Will have to assume that if there's an expiry date bigger than today then that account was active at each of those points in time. I created a numbers table from 1 to 100.
3
1756
by: ajcolburn | last post by:
Hi there, I have 2 tables, shopOrder and wholesaleOrder, each have the following structure: orderID, orderDate, orderTotal I want to generate a report with the following structure, between two given dates: Date, Number of Wholesale Orders, Wholesale Orders Total, Number of Shop Orders, Shop Orders Total
4
1397
by: mak1084 | last post by:
$qselect = 'SELECT ticketID,ticket.created,subject,dept_name,name,email,source,ticket.ticket_id,ticket.dept_id,ticket.staff_id '. ',status,isoverdue,pri.* '; $qfrom=' FROM '.TICKET_TABLE.' ticket LEFT JOIN '.DEPT_TABLE.' dept ON ticket.dept_id=dept.dept_id '. ' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON ticket.priority_id=pri.priority_id '. ' LEFT JOIN '.TICKET_LOCK_TABLE.' tlock ON ticket.ticket_id=tlock.ticket_id...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.