|
kiridu
Starting Member
USA
4 Posts |
Posted - 01/19/2013 : 11:06:41
|
Hello,
Newbie to SQL..
I have a drop down list and an existing table.
I want to code:
If someone selects part_code '1389' i would to take the qty of part_code '11040' and add it to sum of '1389' then grouping them by cost_ctr and If someone selects part_code '1404' i would to take the qty of part_code '1354' and add it to sum of '1404' then grouping them by cost_ctr
below is the table: cost_ctr---part_Code--qty----sum1 2000------11040------100------0 2000------1389------50------100 3000------1389------750 -----275 3000------11040------200------0 2000------1404------500 ------600 2000------1354------100 ------0 3000------1404------500 ------600 3000------1354------100 ------0
Code so far: (only works with one part code 1389, need to also work with 1404)
Select B.cost_ctr,part_Code,qty,Case when part_code=1389 then A.sum1 Else 0 End as sum1 from dbo.test123 B INNER JOIN (Select SUM(qty)as sum1,Cost_Ctr from dbo.test123 WHERE part_code IN ('1389','11040') GROUP by Cost_ctr) A on A.Cost_Ctr=B.Cost_Ctr
thanks for the help... |
Edited by - kiridu on 01/19/2013 11:09:18
|
|