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.
Author |
Topic |
kiridu
Starting Member
4 Posts |
Posted - 2013-01-19 : 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_ctrbelow is the table:cost_ctr---part_Code--qty----sum1 2000------11040------100------02000------1389------50------1003000------1389------750 -----2753000------11040------200------02000------1404------500 ------6002000------1354------100 ------03000------1404------500 ------6003000------1354------100 ------0Code 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_Ctrthanks for the help... |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2013-01-19 : 11:58:12
|
What is expected Output? |
|
|
|
|
|