SQL Script with case and calculation

I need a SQL script that will look at two columns, determine which column is not zero and then multiply that column by a third column.
Example: Select A, B, C from mytable. On each row either B will have a non-zero value or  C will, but never both. The end result is that I need to get the one non-zero value and mulitply it by column A. I currently have what is below but I cannot get the syntax right for it to allow the mulitplication. If there is a better way than the Case please let me know.


SELECT Itemnmbr,'PostingCost' =
     CASE
          WHEN ext_assemble_qty_posting_cost = 0.00 THEN ext_stock_qty_posting_cost
                  ELSE ext_assemble_qty_posting_cost
     END
FROM bm30300
LVL 1
rwheeler23Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:

select *, valfield = (case when afield > 0 then afield else bfield end) * cfield
from tablename

0
tigin44Commented:
try a script like this

SELECT result =
      CASE WHEN column1 <> 0 and column2 = 0 THEN column1
             WHEN column2 <> 0 and column1 = 0 THEN column2
     END * column3
FROM TableName
0
MohammedUCommented:

SELECT Itemnmbr,'PostingCost' =
     CASE
          WHEN b = 0 THEN a*c
          WHEN c= 0 then a*b  
     END
FROM bm30300
0
ErnariashCommented:

rwheeler23, There is nothing wrong with your case query..just add the multiplication..please check if your need cast your columns to the proper datatype.
SELECT Itemnmbr,'PostingCost' = 
     CASE
          WHEN ext_assemble_qty_posting_cost = 0.00 THEN ext_stock_qty_posting_cost
                  ELSE ext_assemble_qty_posting_cost
     END * Acolumn
FROM bm30300

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.