Today I will show you how you can implement it using SQL stored procedure. There are several way to do this in SQL, Here are two SQL script examples that you can use:
Using RIGHT function
SELECT @InvoiceNumber=RIGHT('00000' + CAST(InvoiceNo AS VARCHAR(5)), 5)
FROM TMPNumbers
/*Increment invoice number holder */
UPDATE TMPNumbers SET InvoiceNo=InvoiceNo+1
GO
Using RIGHT AND REPLICATE function
SELECT @InvoiceNumber=RIGHT(REPLICATE('0', 5) + CAST(InvoiceNo AS VARCHAR(5)), 5)
FROM TMPNumbers
/*Increment invoice number holder */
UPDATE TMPNumbers SET InvoiceNo=InvoiceNo+1
GO
For more SQL Coding Tips and Tricks, subscribe now
0 comments:
Post a Comment