2014-06-10 75 views
0

我試着在下面的SQL查詢添加一個,如果其他類型的函數SQL查詢,如果Statment

SELECT  OEEL.invoicedt, UCASE(OEEL.whse) AS Whse, OEEL.orderno, OEEL.ordersuf, OEEL.custno, UCASE(OEEL.shipto) AS Shipto, UCASE(OEEL.slsrepin) AS Slsrepin, 
        UCASE(OEEL.slsrepout) AS Slsrepout, OEEL.returnfl, OEEL.netamt, OEEL.wodiscamt, OEEL.discamtoth, OEEL.qtyship, OEEL.commcost, ICSS.csunperstk, UCASE(ICSD.name) AS Name, 
        UCASE(ICSD.region) AS Region, UCASE(OEEL.prodcat) AS Prodcat, UCASE(SASTA.descrip) AS Descrip, UCASE(OEEL.transtype) AS Transtype, UCASE(ARSS.user2) AS User2, 
        OEEL.transdt, ICSS.transdt AS "ICSS.Transdt", ICSD.transdt AS "ICSD.Transdt", SASTA.transdt AS "SASTA.Transdt", ARSS.transdt AS "ARSS.Transdt", { fn CURDATE() } AS CURDATE1, { fn CURTIME() } AS CURTIME2, 
        OEEL.lineno 

FROM   { oj { oj { oj { oj PUB.oeel OEEL LEFT OUTER JOIN 
         PUB.icss ICSS ON OEEL.cono = ICSS.cono AND OEEL.shipprod = ICSS.prod AND OEEL.icspecrecno = ICSS.icspecrecno } LEFT OUTER JOIN 
         PUB.icsd ICSD ON OEEL.cono = ICSD.cono AND OEEL.whse = ICSD.whse } LEFT OUTER JOIN 
         PUB.sasta SASTA ON OEEL.cono = SASTA.cono AND OEEL.prodcat = SASTA.codeval } LEFT OUTER JOIN 
         PUB.arss ARSS ON OEEL.cono = ARSS.cono AND OEEL.custno = ARSS.custno AND OEEL.shipto = ARSS.shipto } 


WHERE  (OEEL.cono = 1) AND (OEEL.invoicedt BETWEEN { d '2014-06-02' } AND { d '2014-06-03' }) AND (SASTA.codeiden IN ('C', 'c')) 


ORDER By OEEL.custno, OEEL.shipto, OEEL.prodcat 

我會的,如果是像

if OEEL.returnfl = False THEN (OEEL.netamt-OEEL.wodiscamt-OEEL.discamtoth) AS "SALES" 
Else (-1*(OEEL.netamt-OEEL.wodiscamt-OEEL.discamtoth)) AS "SALES" 

回答

0

您可以添加CASE語句您查詢

CASE WHEN OEEL.returnfl = 'False' THEN (OEEL.netamt-OEEL.wodiscamt-OEEL.discamtoth) ELSE (-1*(OEEL.netamt-OEEL.wodiscamt-OEEL.discamtoth)) END AS "SALES"