i think what you should do is to remove the preceding 0s from prodcode field to make values match. then apply the logic and you should get the intended results
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/