user1086159
user1086159

Reputation: 1055

Incorrect syntax

I have a selection of sql code that I keep getting an 'Incorrect syntax' error on.

I cannot see what is causing the issue.

Can anyone point out the obvious to me? I maybe have been staring at the code for too long to see it now!!

My code is :-

DECLARE @CostCatID AS Int

SELECT * FROM vwREP_GP_ContractProjectPurchaseRpt
WHERE PACOSTCATID IN (@CostCatID)
AND (DOC_DATE >= @DateFrom) 
AND (DOC_DATE  <= @DateTo)
order by 1

and the full error message I get is:-

Incorrect syntax near ';'

I know it is going to be obvious to most people but for the life of me in my tired state I cannot get this to work.

Thanks in advance.

(all work is being done in sql Server Management Studio 2005)

Upvotes: 1

Views: 463

Answers (4)

Widor
Widor

Reputation: 13285

For once, the SQL error message is quite helpful:

Incorrect syntax near ';'

and you have the string >= unquoted in you code.

I think you meant to use >= and <= instead.

Upvotes: 0

Marco
Marco

Reputation: 57593

You're using &gt; and &lt;: did you copy from a web page?

DECLARE @CostCatID AS Int

SELECT * FROM vwREP_GP_ContractProjectPurchaseRpt
WHERE PACOSTCATID IN (@CostCatID)
AND (DOC_DATE >= @DateFrom) 
AND (DOC_DATE <= @DateTo)
order by 1

Upvotes: 0

Taryn
Taryn

Reputation: 247880

Not sure why you are using &gt; and &lt;, you need to use > and <

DECLARE @CostCatID AS Int

SELECT * FROM vwREP_GP_ContractProjectPurchaseRpt
WHERE PACOSTCATID IN (@CostCatID)
AND (DOC_DATE >= @DateFrom) 
AND (DOC_DATE  <= @DateTo)
order by 1

Upvotes: 0

Mathew Thompson
Mathew Thompson

Reputation: 56459

&gt; and &lt;? Why are you encoding > and <? There's your problem. Try:

DECLARE @CostCatID AS Int

SELECT * FROM vwREP_GP_ContractProjectPurchaseRpt
WHERE PACOSTCATID IN (@CostCatID)
AND (DOC_DATE >= @DateFrom) 
AND (DOC_DATE <= @DateTo)
ORDER BY 1

Upvotes: 4

Related Questions