Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Increment a number within a string
Message
 
 
To
04/12/2007 14:03:50
Greg Rowe
Memphis Police Department
Memphis, Tennessee, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01273115
Message ID:
01273116
Views:
17
>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--
Previous
Reply
Map
View

Click here to load this message in the networking platform