Question : Error on one line and not on the other

The first line of code works.  I have the second one giving me an error regarding the <.  I am using the same syntax for the PassedDate and the PassedDateEnd.  I don't see why it isn't working.

Thanks in advance!

Tanya
Code Snippet:
1:
2:
3:
4:
5:
This line works:
QueryString = "SELECT EquipmentMasterReadings.Equipment_Number, Max(EquipmentMasterReadings.Reading) AS CurrentMonthEnding, reading_date  FROM EquipmentMasterReadings GROUP BY EquipmentMasterReadings.Equipment_Number, reading_date HAVING reading_date  >= " & "'" & PassedDate & "'" & " AND reading_Date <= " & "'" & PassedDateEnd & "'" & " ORDER BY EquipmentMasterReadings.Equipment_Number, Max(EquipmentMasterReadings.Reading);"

Get Error on following line:  "Incorrect syntax near '<'."
        QueryString = "SELECT LubeTransactions.Equipment_Number, Sum(LubeTransactions.Quantity) AS SumOfQuantity, LubeTransactions.Lube_Type, Sum(IIf([Oil_Change]<>" & "'" & "Yes" & "'" & ",[Quantity],Null)) AS 40wt, Sum(IIf([Oil_Change]=" & "'" & "Yes" & "'" & ",[Quantity],Null)) AS oilchange FROM FuelConsumptionTemp WHERE Transaction_Date >= " & "'" & PassedDate & "'" & " AND Transaction_Date  <=  " & "'" & PassedDateEnd & "'" & "  GROUP BY LubeTransactions.Equipment_Number, LubeTransactions.Lube_Type HAVING LubeTransactions.Lube_Type = " & "'" & "Engine Oil 40WT" & "'" & " ORDER BY LubeTransactions.Equipment_Number;"

Answer : Error on one line and not on the other

TanyaDH,

No, SQL Server does not use IIf().  It uses CASE...WHEN...THEN...END

Patrick
Random Solutions  
 
programming4us programming4us