Mar 30, 2013

Get Next Number with REPLICATE In SQL Server

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

No comments:

Post a Comment

What is the use of n-tier architecture and 3-tier architecture?

how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...