Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join error for date range

Status
Not open for further replies.

Ebes1099

Technical User
Jul 8, 2009
156
0
0
US
I am trying to join two tables on ID1, ID2 and when Date > Start AND < End but I keep getting an error when I add the date fields in. Just joining on ID1 and ID2 works fine, but I'm of course getting duplicated records because in my right table I can have two lines for ID1, ID2 with a different start and end date. I'm trying to join so I can grab a field from my right table and add it into my results.

Typically in SQL Server I would just do a join on LeftTable.ID1 = RightTable.ID1 AND LeftTable.ID2 = RightTable.ID2 AND LeftTable.Date >= RightTable.Start AND Date < RightTable.End, but I can't get that to work in Access. It's giving me a message saying I have an error in my Join expression is not supported. I know the SQL that Access supports is a little different than SQL server so if someone could help me out that would be great.

This works:
SQL:
FROM All_Claims LEFT JOIN tmp_Duration2 ON (All_Claims.RPID = tmp_Duration2.RPID) AND (All_Claims.PATID = tmp_Duration2.PATID)

This doesn't:
SQL:
FROM All_Claims LEFT JOIN tmp_Duration2 ON (All_Claims.RPID = tmp_Duration2.RPID) AND (All_Claims.PATID = tmp_Duration2.PATID) AND (All_Claims.[DOSDATE]>=tmp_Duration2.Rvsd_Cnt_Start_Dt) AND (All_Claims.[DOSDATE]<DateAdd("y",1,tmp_Duration2.Rvsd_Cnt_Start_Dt)
 
Hmmmmm, DOSDATE: is that a real date or a string?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Please add carriage returns in your posting. It makes your SQL much easier to read.

Do you realize that DateAdd("y",1,tmp_Duration2.Rvsd_Cnt_Start_Dt) adds a day and not a year? If you want to add a year, use "yyyy".

I'm not sure what range you expect or if the fields are actual dates and if they contain time values. You might want to try:

SQL:
FROM All_Claims LEFT JOIN tmp_Duration2 ON (All_Claims.RPID = tmp_Duration2.RPID) 
 AND (All_Claims.PATID = tmp_Duration2.PATID) 
 AND (tmp_Duration2.[DOSDATE] Between tmp_Duration2.Rvsd_Cnt_Start_Dt AND 
 DateAdd("yyyy",1,tmp_Duration2.Rvsd_Cnt_Start_Dt) -0.0001)

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top