Lawrence Salvucci
asked on
SQL Query Syntax Error
I have this SELECT query that seems to work fine in SQL 2014 but when I try to run it in SQL 2008 I get an error that says "Incorrect syntax near '<'
Can anyone explain why I get this error in 2008 but not in 2014?
Can anyone explain why I get this error in 2008 but not in 2014?
SELECT P.fpono As PONo, P.forddate As OrderDate, P.fvendno As VendorNo, P.fcompany As VendorName, P.fbuyer As Buyer, P.fstatus As POStatus,
RTRIM(P1.fpartno) As PartNo, P1.fdescript As PartDesc, P1.fordqty As OrderQty, P1.frcpqty As RecQty, P1.fucostonly As UnitCost, P1.forgpdate As OrigDate, P1.flstpdate As LastDate, P1.fmeasure As UoM,
'$'+convert(varchar(10),Convert(money,(P1.fordqty) * (P1.fucostonly))) As ExtCost, '$'+convert(varchar(10),Convert(money,IIF((P1.fordqty-P1.frcpqty)*P1.fucostonly<0,0,(P1.fordqty-P1.frcpqty)*(P1.fucostonly)))) As ExtCostOpen, IIF((P1.fordqty-P1.frcpqty)<0,0,P1.fordqty-P1.frcpqty) As OpenQty
FROM dbo.pomast AS P
INNER JOIN dbo.poitem AS P1
ON P1.fpono = P.fpono
INNER JOIN dbo.apvend As A1
ON A1.fvendno = P.fvendno
WHERE (P.fstatus = 'OPEN') AND (A1.fcacctnum = '5010001');
ASKER
Thanks Jim. I appreciate the help. I'm getting another error now that says "incorrect syntax near 'As'. Am I missing something else for the "As OpenQty" syntax?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both for your help. I will post the errors from SSMS the way you outlined, Jim. Thanks again and I'm sure I'll be posting back again. I'm still learning....
You'll have to use CASE instead of IIF.
Change this
Open in new window
to thisOpen in new window
If it helps (no pun intended), here's an article I wrote called SQL Server CASE Solutions that is a handy tutorial on CASE.