SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 adding column value to a specific row. please help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kiridu
Starting Member

USA
4 Posts

Posted - 01/19/2013 :  11:06:41  Show Profile  Reply with Quote
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

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 01/19/2013 :  11:58:12  Show Profile  Reply with Quote
What is expected Output?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000