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
 General SQL Server Forums
 New to SQL Server Programming
 adding column value to a specific row. please help

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_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...

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2013-01-19 : 11:58:12
What is expected Output?
Go to Top of Page
   

- Advertisement -