Using if then statement in select query

G

Guest

I am trying to evaluate a field and perform one of two different calculations
based upon the field and showing the correct result in a different field.
Basically, if Order PS is >= 1 I want one calculation done and displayed, if
Order PS is <1 I want a different calculation done and displayed. Any help? I
keep getting an error message regarding the syntax of my End If???

SELECT Contracts.[Purchasing Source], Contracts.[Contract Code], [Contracted
Drugs].DF, Contracts.NDC, [Contracted Drugs].LN, [Contracted Drugs].BN,
[Contracted Drugs].GNN, [Contracted Drugs].BB_P, [Contracted Drugs].CSP,
[Contracted Drugs].PS, [Contracted Drugs].[BB_P Eff Date],
Contracts.[Purchasing Preference], Contracts.[Business Div],
Contracts.[Pricing Eff Date], Contracts.[Pricing End Date], Contracts.[Order
PS UOM], Contracts.[Order CSP UOM], Contracts.[Order PS], Contracts.[Order
CSP], Contracts.[Contract Price], Contracts.[AWP Based %], Contracts.[WAC
Based %], Contracts.[Admin Fee], Contracts.[Fixed Rebate], Contracts.[Incr
Fee], Contracts.[Down Chg1], Contracts.[Down Chg2], Contracts.[Down Chg3],
Contracts.Active, Contracts.Notes, Contracts.[Updated by], Contracts.[Update
date], Contracts.[Order PS]*Contracts.[Order CSP] AS Exp1,IfContracts.[Order
PS]>=1,Then (Exp2 =Contracts.[Contract Price]/[Exp1]) , ElseIf
(Contracts.[Order PS] < 1), Then (Exp2 =Contracts.[Contract Price]*[Exp1])
End If,

FROM [Contracted Drugs] INNER JOIN Contracts ON [Contracted Drugs].NDC =
Contracts.NDC

WHERE (((Contracts.[Purchasing Source]) Like "*" & [Enter Source] & "*"));
 
G

Guest

UNTESTED Try this in your SQL statement for the IIF --
IIF(Contracts.[Order PS] >=1, Contracts.[Contract Price]/(Contracts.[Order
PS]*Contracts.[Order CSP]), Contracts.[Contract Price]*( Contracts.[Order
PS]*Contracts.[Order CSP]) ) AS Expr2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top