Skip to Content
0
Aug 04, 2009 at 03:03 PM

Problem with Query

25 Views

Hi All,



I have been trying to design a query and have come across a very annoying problem. My query below works fine until I try to change the WHERE T0.CreateDate statement to ask the user for an input date.



SELECT DISTINCT
T0.CardCode, T0.CardName, CASE WHEN t0.cardtype = 'L' THEN 'Lead' WHEN t0.cardtype = 'C' THEN 'Customer' WHEN
t0.cardtype = 'S' THEN 'Supplier'

END AS , T0.CreateDate, T0.Currency, dbo.OCRG.GroupName, T0.Address, T0.Block,

T0.City, T0.County, T0.Country, T0.ZipCode, T0.State1, T0.U_BNVATNo AS , CASE WHEN t0.vatstatus = 'N' THEN
'Exempted' WHEN t0.vatstatus = 'Y' THEN 'Liable' WHEN t0.vatstatus = 'E' THEN 'EU' END AS ,

bo.OCTG.PymntGroup, CASE WHEN T0.QryGroup1 = 'Y' THEN 'Y' END AS , CASE WHEN T0.QryGroup2 = 'Y' THEN 'Y' END

AS , CASE WHEN T0.QryGroup3 = 'Y' THEN 'Y' END AS , CASE WHEN T0.QryGroup4 = 'Y' THEN 'Y' END AS ,

CASE WHEN T0.QryGroup5 = 'Y' THEN 'Y' END AS Decorative, CASE WHEN T0.QryGroup6 = 'Y' THEN 'Y' END AS Labelling

FROM dbo.OCRD AS T0 INNER JOIN
dbo.OCRG ON T0.GroupCode = dbo.OCRG.GroupCode INNER JOIN
dbo.CRD1 AS T1 ON T0.CardCode = T1.CardCode INNER JOIN
dbo.OCTG ON T0.GroupNum = dbo.OCTG.GroupNum
WHERE T0.CreateDate <= '01.08.09'




When I change the last line to

WHERE T0.CreateDate <= '[%0]'

with or without ' ' marks. I get an error saying



1). [ODBC SQL Server Driver][SQL Server]Incorrect syntax near '0'. 2).
[ODBC SQL Server Driver][SQL Server]Statement '' (SEWSY)(s) could not be prepared.

Can anyone help point out what I have done wrong please?

Thanks In Advance

John