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
 General SQL Server Forums
 New to SQL Server Programming
 Getting record with Max date within a year

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2010-01-20 : 12:43:44
Need to grab records that have the maximum trx_dt in 2009.

Table is iminvtrx_sql

Record item_no Trx_dt Qty
1 ABC 5/2/2009 5
2 ABC 11/3/2009 7
3 ABC 1/19/2010 1
4 123 4/5/2009 4
5 123 12/31/2009 9


In the example above I would only want records 2 and 5

Sachin.Nand

2937 Posts

Posted - 2010-01-20 : 13:08:30
select item_no,max(Trx_dt),sum(Qty)from tbl
where datepart(yy,Trx_dt)=2009
group by item_no

PBUH
Go to Top of Page
   

- Advertisement -