Problem with query containing date criteria

LemonTwist

New member
Local time
Today, 16:00
Joined
Aug 5, 2008
Messages
7
I am stuck on a make-table query which involves date criteria. When I try to run the query, I get an error message saying "ODBC call failed. [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting datetime from character string. (#241)."

In my query design view, there are 2 tables: one containing the actual data and the other is a date table containing the current weekend date (ie 19/09/2008), month start date (01/09/2008) and month end date (30/09/2008). I have checked that all the dates used in the both tables are in Date/Time format. The 2 tables are not joined in any way; the date table is just used for the query criteria.

This is how the query looks in SQL view:
Code:
SELECT DATA.CustomerNo AS customer_no, DATA.Inceptdate AS inception_date, DATA.Due_Date, DATA.Current_Date, DATA.CanxDate AS can_trans_date, DATA.LapseDate INTO DataPool
FROM DATA, DATES
WHERE (((DATA.Inceptdate)<[DATES].[START]) AND ((DATA.Due_Date) Between [DATES].[START] And [DATES].[WEEKEND])) OR (((DATA.Inceptdate)<[DATES].[START]) AND ((DATA.Current_Date) Between [DATES].[START] And [DATES].[WEEKEND])) OR (((DATA.Inceptdate)<[DATES].[START]) AND ((DATA.Current_Date) Between [DATES].[START] And [DATES].[WEEKEND]) AND ((DATA.CanxDate)>([DATA].[current_date]+26))) OR (((DATA.Inceptdate)<[DATES].[START]) AND ((DATA.LapseDate) Between [DATES].[START] And [DATES].[WEEKEND])) OR (((DATA.Inceptdate)<[DATES].[START]) AND ((DATA.Current_Date) Between [DATES].[START] And [DATES].[WEEKEND]) AND ((DATA.CanxDate)<([DATA].[current_date]+26))) OR (((DATA.Inceptdate)<[DATES].[START]) AND ((DATA.Due_Date) Between [DATES].[START] And [DATES].[WEEKEND]) AND ((DATA.CanxDate)>(DateAdd('m',-1,[DATA].[due_date]))));

Does anyone know why this error is appearing, and what I need to do to fix the query?
Thank you in advance.
 
Don't you need to wrap your dates with a #? As in #date#?
 
Don't you need to wrap your dates with a #? As in #date#?

I did think about that, but when I tried it I just got an error. I think it's because I'm using parameters rather than actual dates in the query.
 

Users who are viewing this thread

Back
Top Bottom