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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with Case statement

Author  Topic 

eljapo4
Posting Yak Master

100 Posts

Posted - 2010-10-29 : 09:49:12
SELECT inInvAdj.FiscalDate,
inInvAdj.InvAdjActySysActNm,
inInvAdjLi.Resc,
inInvAdjLi.OrigPrQty AS Qty,
CASE
WHEN inInvAdjLi.PrimQtyUM <> inInvAdjLi.OrigPrQtyUM THEN
(inInvAdjLi.PrimQty * bcConvFactor.ToFactor)
ELSE inInvAdjLi.PrimQty
END AS Correctie,
fdCostRole.InvStdOneCurAmt AS StandaardCost,
fdBasResc.StdCostCur AS Currency,
inInvAProf.Description,
inInvAdjLi.AdjActyType,
CASE
WHEN inInvAdjLi.AdjActyType = '2' THEN
((Correctie-inInvAdjLi.OrigPrQty) * fdCostRole.InvStdOneCurAmt)
ELSE (inInvAdjLi.PrimQty * fdCostRole.InvStdOneCurAmt)
END AS Waarde


Hi as you can see i'm trying to subtract ((OrigPrQty from Correctie) * InvStdOneCurAmt) when AdjActyType = '2' but the problem I have at the minute is that the results being returned are displaying (OrigPrQty * InvStdOneCurAmt) even though the AdjActyType = '2' for this order.

Can anyone spot what I have done wrong and help me out please? Thanks

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-29 : 09:57:43
what is datatype of inInvAdjLi.AdjActyType ?
Go to Top of Page

eljapo4
Posting Yak Master

100 Posts

Posted - 2010-10-29 : 10:09:20
inInvAdjLi.AdjActyType = (int, not null)
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-10-29 : 10:11:07
If I'm not mistaken (and I could be), it doesn't know what Correctie is in the second CASE statement.
Go to Top of Page

eljapo4
Posting Yak Master

100 Posts

Posted - 2010-10-29 : 10:17:46
is there a sure way for me to test what values is being inputted at the time the 2nd case statement executes?
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-10-29 : 11:20:05
SELECT inInvAdj.FiscalDate,
inInvAdj.InvAdjActySysActNm,
inInvAdjLi.Resc,
inInvAdjLi.OrigPrQty AS Qty,
CASE
WHEN inInvAdjLi.PrimQtyUM <> inInvAdjLi.OrigPrQtyUM THEN
(inInvAdjLi.PrimQty * bcConvFactor.ToFactor)
ELSE inInvAdjLi.PrimQty
END AS Correctie,
fdCostRole.InvStdOneCurAmt AS StandaardCost,
fdBasResc.StdCostCur AS Currency,
inInvAProf.Description,
inInvAdjLi.AdjActyType,
Correctie

Try that, see what the value is for the last column (if it even executes).
Go to Top of Page
   

- Advertisement -