select top 1 CONVERT(int, ISNULL( REPLACE( ClientCode , '{0}' ,''),0) ) +1 as MaxValue from CRM_Client where ClientCode like '{0}%' " + "order by CONVERT(int, REPLACE( ClientCode , '{0}' ,'')) desc