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)
 Unique max costs

Author  Topic 

pizzojm
Starting Member

20 Posts

Posted - 2003-08-26 : 14:59:40
I have a cost table which stores cost for a store and item everytime the cost is updated. It inserts a new row each time this happens with the date, it does not simply update the existing record. The problem is I need a daily report that pulls the most recent cost for every item and every associated store. I can't seem to do this and retrieve one record and one date. The table schema is as follows and any help would be greatly appreciated!...

cost_key serial
item_num integer
store_num smallint
cost_date date
cost money(10,4)

nr
SQLTeam MVY

12543 Posts

Posted - 2003-08-26 : 15:47:26
select *
from tbl
where cost_date = (select max(t1.cost_date) from tbl t1 where t1.cost_key = tbl.cost_key and t1.item_num = tbl.item_num and t1.store_num = tbl.store_num)


Not sure what cost_key is - you may have to drop it from the subquery.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -