Hi all,I usually use Oracle databases, but have a query on a SQL Server database that I need to amend.in Oracle I use the DECODE function to satisfy my current problem.Can this be used in SQL in the same way? as i'm having problems.my original code is:SELECT projects.title, WIPUNION.Client, WIPUNION.Project, Sum (WIPUNION.Quantity)FROM DSTRMPROD.dbo.projects projects, (SELECT ppa_WIP.Client, ppa_WIP.Project, ppa_WIP.Quantity, ppa_WIP.Chargeable as chargeable FROM dbo.ppa_WIP ppa_WIP WHERE ppa_WIP.Client LIKE 'LGL02UK' AND ppa_WIP.Status=0 Union ALL SELECT ppa_TRANS.Client, ppa_TRANS.Project, ppa_TRANS.Quantity, 2 as chargeable FROM dbo.ppa_TransControl ppa_TRANS WHERE ppa_TRANS.Client LIKE 'LGL02UK' )WIPUNION WHERE WIPUNION.Project = PROJECTS.projid Group BY WIPUNION.Client, WIPUNION.Project, PROJECTS.Title, WIPUNION.Chargeable
i was hoping to use the function: SELECT projects.title, WIPUNION.Client, WIPUNION.Project, Sum (WIPUNION.Quantity),sum(DECODE(WIPUNION.chargeable, 1, WIPUNION.QUANTITY)) as Charge,sum(DECODE(WIPUNION.chargeable, 0, WIPUNION.QUANTITY)) as NonCharge
it doesn't seem to work.can anyone tell me if i'm going down the wrong path?alternativley I DID try:CASE WHEN WIPUNION.chargeable = 1 then SUM(WIPUNION.QUANTITY)Else 0 endetc..
but this didn't work either..thanks in advance,Matt