Because the monthid is a varchar and not a proper datetime column and you need to get the "latest" in terms of time, you have to convert the value in the monthid to a datetime datatype. Your design itself is bad. To workaround try something like this:
NewCol = max( convert(datetime,'20' + substring(monthid,5,2) + substring(monthid,1,3) + '01') )
Now you can do a group by on the prodid, custid, spid and get a max of above concatenation.
Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/