>I need to imcrement a number within a string such as ME20070019. I need the ME to remain as a constant. The 2007 is the current year. I need to be able to increment the 0019 by one for each time the record is written to the file.
DECLARE @strkey varchar(50), @strkeynext varchar(50)
SET @strkey = 'ME20070019'
SET @strkeynext = LEFT(@strkey,6) + RIGHT( '0000' + CAST(SUBSTRING(@strkey,7,4) + 1 AS varchar(10)), 4)
SELECT @strkeynext
--sb--