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
 Transact-SQL (2000)
 How to SUM data from same column into few

Author  Topic 

BusteR
Starting Member

17 Posts

Posted - 2004-04-15 : 03:53:26
Hi

Subject is not well said but... it's not easy to describe my prob. with one sentence.
Table structure:
key x y z
1 1 1 23
2 1 2 45
3 1 7 32
4 1 3 15
5 2 3 67
6 2 9 45

etc.
X would be something like a document number, Y would be a brand and Z will be a quanity. I have to create a few groups of brands [1<>3, 4<>6, 7<>9 ...] and i have to sum quanities for each group and get it in 1 row for each document. It should look like that:
x G1 G2 G3
1 83 0 32
2 67 0 45

etc.

I hope i made myself clear [sorry for my poor english and lack of imagination in this one]... it is very important to me and i have no idea how to get those 3 columns out of one :/

I would be gratefull for any help.

Best Regards

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-04-15 : 04:03:58
I think what you are trying to do can be answered by looking at this thread.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=34037



Duane.
Go to Top of Page

BusteR
Starting Member

17 Posts

Posted - 2004-04-15 : 04:09:07
Thank you very very much!
:)
Go to Top of Page

BusteR
Starting Member

17 Posts

Posted - 2004-04-16 : 03:57:54
Hi again...
unfortunately database has changed and now...
i have to get a price of things that are in db. Price is in database but in diffrent table then quanity... everything would be perfect, but... in groups there are diffrent prices..so i've trided to do it like this:
Sum(CASE when ob_TowId IN (5, 6, 7, 8, 9, 10, 11, 12, 13) AND ob_TowId = koszt_TwId Then ob_Ilosc * koszt_Cena else 0 end)
where
ob_TwoId, koszt_TwId = Id of product in 2 tables
ob_Ilosc = quanity
koszt_Cena = price

but it gets me wrong results, is there any way to do it in one query or do i have to create a sum for every product?
It would be nothing but.. when i do it in one SUM() then it is easier for me to do it dynamic in php.

Best regards.
Go to Top of Page
   

- Advertisement -