How we can generate a alpha-numeric CustomerID in sql server
How we can generate a alpha-numeric CustomerID in sql server. For example, SC-12-10-26-0001, here SC is fix for every customer, 12 is showinng current year,10 is showing current month, 26 is showing current date and 0001 is showing first cutomer of the current date. I want to generate ID according to this. If new year, month or date is coming then it's change accroding to this. Pl'z guide me how we can solve this.......
Sivaraman DhamodaranPosted Oct 26, 2012, 2:49 AM
SELECT "SC-" + REVERSE(CONVERT(VARCHAR(8), GETDATE(), 5)) + "-" + (User_Function) AS GeneratedId
Here,
User_Function is the one that will return count(*) of the table and perform Padding with leading zeros. You should write one.
Note: I don't have SQL server now. Other member's can help you, if this does't work.