Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 IF statement issue

Author  Topic 

dzisaacs
Starting Member

2 Posts

Posted - 2006-03-20 : 10:21:55
This is my query...this query works in microsoft access


SELECT CombustibleItems.IdCombItem,
CombustibleItems.IdMovComb,
CombustibleItems.Manguera,
Inventory.[Item Number],
Inventory.Description,
CombustibleItems.Vendedor,
CombustibleItems.GalonesInicial,
CombustibleItems.GalonesFinal,
Round(Round([GalonesFinal],3)-Round([GalonesInicial],3)-Round([CalibracionGalones],3),3) AS GalonesVenta,
CombustibleItems.MontoInicial,
CombustibleItems.MontoFinal,
[MontoFinal]-[MontoInicial]-[CalibracionMonto] AS MontoVenta,
CombustibleItems.Descuento,
CombustibleItems.CalibracionGalones,
CombustibleItems.CalibracionMonto,
Inventory.Taxable,
Inventory.Taxable2,
Inventory.[Inventory Account],

IIf([GalonesFinal]-[GalonesInicial]-[CalibracionGalones],Round(([MontoVenta]/[GalonesVenta]),2),0) AS PrecioGalon

FROM (Inventory INNER JOIN Mangueras ON Inventory.[Item Number] = Mangueras.Producto) INNER JOIN CombustibleItems ON Mangueras.Manguera = CombustibleItems.Manguera



On microsoft access i'm able to do the IIf inside the select part....how can i do that on microsoft sql server?

If i try to do this query on sql server i get this error
Error in list of function arguments: 'IIf' not recognized.
Missing FROM clause.
Unable to parse query text.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-03-20 : 10:29:21
From within a SELECT statement, "iif" logic can be handled with a CASE statement.
see CASE in Books Online


EDIT:
I'm not an Access guy but doesn't the first arguement need to evaluate to either true or false?


Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-21 : 01:03:53
>>I'm not an Access guy but doesn't the first arguement need to evaluate to either true or false?

Yes it is

IIF(condition=True, True_Part,Else_Part)

dzisaacs, you are missing some condition. Did you execute it successfully in Access?



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -