I am trying to create a view which will bring me back the most recent FiscalCalYear and FiscalCalPeriod from a table along with the rest of the details in the row.
It needs to be dynamic so I thought using a max() would work, however, unless I hard code in the where FiscalCalYear = 2010 I can't get the rows back. I've tried a myriad of ideas, but they all bring back all rows for all years and periods. Any help would be greatly appreciated.
select ItemCode,
WareHouseCode,
FiscalCalYear,
FiscalCalPeriod,
BeginningBalQty,
BeginningBalDollarAmt,
BeginningBalExtendedStdCost,
PeriodChangeDollarAmt,
PeriodChangeExtendedStdCost
from #temp
--where FiscalCalYear = 2010
Group by ItemCode,
WareHouseCode,
FiscalCalYear,
FiscalCalPeriod,
BeginningBalQty,
BeginningBalDollarAmt,
BeginningBalExtendedStdCost,
PeriodChangeDollarAmt,
PeriodChangeExtendedStdCost
having FiscalCalYear = max(FiscalCalYear)
and FiscalCalPeriod = max(FiscalCalPeriod)
order by FiscalCalYear,
FiscalCalPeriod,
WareHouseCode
