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 can I do this?

Author  Topic 

rtr1900
Starting Member

48 Posts

Posted - 2007-11-27 : 06:54:39
Hi,

I have a table and the layout is this

Cod_article
Name
amount
Price
Expired date
box

During the process of registration of products we get a table which has repeated Articules, but different prices/expired dates/boxes. How can select them so that I get for every article a line with the sum of that article, BUT keeping in mind the filter of the price/expired datebox. I tried a lot of things using DIstinct / Sum,... but always I get it wrong. For example:

Cod_Art Name Amount price Exp_date Box
1234 I-Cream 5 5.5 12/12 1
1234 I-Cream 5 5.5 12/12 1
1234 I-Cream 5 5.5 12/12 2
1234 I-Cream 5 5.5 11/12 1

Should give me as result:

Cod_Art Name Amount price Exp_date Box
1234 I-Cream 10 5.5 12/12 1
1234 I-Cream 5 5.5 12/12 2
1234 I-Cream 5 5.5 11/12 1

is this possible? I find it difficult to filter on so many cels, as I have to check over the same table.

Any help is welcome!!

regards,

Johny

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-27 : 07:29:03
Try

Select Cod_article,Name,amount,Price,[Expired date],min(box) as box from table
group by Cod_article,Name,amount,Price,[Expired date]


Madhivanan

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

rtr1900
Starting Member

48 Posts

Posted - 2007-11-27 : 07:44:14
madhivanan,

T H A N X !!!!!!!

You just hit the jackpot!!

I added the SUM() and now I get back all the rows, summed the totalamount of that sepecial product. Just what I needed.

So this is with the GROUP BY command? I will take a look at it, as it helped me a lot!

Thx again for you help and fast reply!!!!

Johny
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-27 : 07:51:58
Well. In case if you are new to sql, learn it

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

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

- Advertisement -