Saturday, February 25, 2012

Dates not working in SQL query

This is the query that gives the error message for 'Oct 9, 2003' on a server
but works correctly on another - what could make this happen on SQL 2000
Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
SELECT count(*)
FROM Contact INNER JOIN
OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
(PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
1, 1980') AND
(PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
(LEFT(OrderHeader.OrderCode, 1) = '1')
AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
NULL)
Regards Jeff
This is the query that gives the error message for 'Oct 9, 2003' on a server
but works correctly on another - what could make this happen on SQL 2000
Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
SELECT count(*)
FROM Contact INNER JOIN
OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
(PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
1, 1980') AND
(PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
(LEFT(OrderHeader.OrderCode, 1) = '1')
AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
NULL)
Regards Jeff
--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.524 / Virus Database: 321 - Release Date: 6/10/2003Jeff
Please refer to BOL for CONVERT function.
"Jeff Williams" <jeff.williams@.hardsoft.com.au> wrote in message
news:#AtCV9SjDHA.1672@.TK2MSFTNGP09.phx.gbl...
> This is the query that gives the error message for 'Oct 9, 2003' on a
server
> but works correctly on another - what could make this happen on SQL 2000
> Server: Msg 241, Level 16, State 1, Line 1
> Syntax error converting datetime from character string.
>
> SELECT count(*)
> FROM Contact INNER JOIN
> OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
> PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
> WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
> (PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
> 1, 1980') AND
> (PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
> (LEFT(OrderHeader.OrderCode, 1) = '1')
> AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
> OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
> NULL)
> Regards Jeff
>
> This is the query that gives the error message for 'Oct 9, 2003' on a
server
> but works correctly on another - what could make this happen on SQL 2000
> Server: Msg 241, Level 16, State 1, Line 1
> Syntax error converting datetime from character string.
>
> SELECT count(*)
> FROM Contact INNER JOIN
> OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
> PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
> WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
> (PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
> 1, 1980') AND
> (PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
> (LEFT(OrderHeader.OrderCode, 1) = '1')
> AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
> OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
> NULL)
> Regards Jeff
>
>
> --
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.524 / Virus Database: 321 - Release Date: 6/10/2003
>

No comments:

Post a Comment