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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Advanced Sum

Author  Topic 

jrich523
Starting Member

4 Posts

Posted - 2006-03-09 : 12:21:16
I have a table of product names (raw materials) and i have a history of when they come in.
so i want to do something like... for each product get the total number in inventory.

table: products
name (pk)

table: inv
name, gross

for each products.name get the sum(inv.gross)
there is obviously more in each table but this is the only data i need to work with for this query..
my sql is pretty weak as it is so this is over my head a bit.. but im pretty sure this can be done.

Thanks
Justin

JoeNak
Constraint Violating Yak Guru

292 Posts

Posted - 2006-03-09 : 12:58:46
select p.[name], sum(isnull(i.gross, '0'))
from products p
left outer join inv i on p.[name] = i.[name]
group by p.[name]
Go to Top of Page

jrich523
Starting Member

4 Posts

Posted - 2006-03-09 : 13:15:01
your my hero, thanks :)
the best part is i barely understand whats its doing lol..
thankfully at this point i dont have to. again, thank you.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-03-09 : 14:09:00
quote:
Originally posted by jrich523
...the best part is i barely understand whats its doing lol..
thankfully at this point i dont have to...



Yes, there's no chance that it's not doing exactly what you hope it's doing.




CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-10 : 03:03:07
Also learn SQL
http://www.w3schools.com/sql/default.asp
http://www.sql.org/sql-database/sql-tutorial/


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -