Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF in the Select statement

Status
Not open for further replies.

DanNorris2000

Technical User
Joined
Nov 10, 2000
Messages
186
Location
US
Trying to implement the following IF statement but without success in my syntax. Can anyone help?

Create sql view V650TY AS;
Select Ledger.pc,Ledger.uw,;
Contracts.ctrsts AS COMMUTED,;
Ledger.dev,Ledger.bookper,ledger.curr,;
IF(ledger.curr)="CAN" then ROUND(MTON(sum(Ledger.osloss * nRate)),2)AS OSLOS
else round(mton(sum(ledger.osloss)),2 as OSLOS;
endif,;
ROUND(MTON(sum(Ledger.osexp)),2)AS osexp,;
 
You can either implement a function call or use an immediate if.

luResult = IIF(condition, result1, result2)

In your case:

Create sql view V650TY AS;
Select Ledger.pc,Ledger.uw,;
Contracts.ctrsts AS COMMUTED,;
Ledger.dev,Ledger.bookper,ledger.curr,;
IIF(ledger.curr)="CAN" ,ROUND(MTON(sum(Ledger.osloss * nRate)),2), round(mton(sum(ledger.osloss)),2) as OSLOS;
,ROUND(MTON(sum(Ledger.osexp)),2)AS osexp,; etc.

HTH,
Weedz (Edward W.F. Veld)
My private project:Download the CrownBase source code !!
 
Looks goid except for a mysterious missing comma error I'm getting after I add the statement:
IIF(ledger.curr)="CAN",ROUND(MTON(sum(Ledger.osloss * nRate)),2),round(mton(sum(ledger.osloss)),2)as OSLOS,;
ROUND(MTON(sum(Ledger.osexp)),2)AS osexp,;
 
You just need the extra parens around the statement:

IIF((ledger.curr)="CAN",ROUND(MTON(sum(Ledger.osloss * nRate)),2),round(mton(sum(ledger.osloss)),2)) as OSLOS Derren
[Mediocre talent - spread really thin]
 
It looks like it should be:

IIF(ledger.curr = "CAN"....

instead of
IIF(ledger.curr) = "CAN"...

Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top