Get Next max value for custom identification of table value
SELECT 'PR' + Substring( '2012-2013', 3, 2 )
+ Replicate('0', 4-Len(Count(*)+1))
+ Cast(Count(*)+1 AS VARCHAR(4)) AS NewCode
FROM tablename
WHERE pro_finyear = '2012-2013'
OUTPUT
=================
NewCode
PR120012
SELECT 'PR' + Substring( '2012-2013', 3, 2 )
+ Replicate('0', 4-Len(Count(*)+1))
+ Cast(Count(*)+1 AS VARCHAR(4)) AS NewCode
FROM tablename
WHERE pro_finyear = '2012-2013'
OUTPUT
=================
NewCode
PR120012
No comments:
Post a Comment