Link to home
Start Free TrialLog in
Avatar of Shezad Ahmed
Shezad AhmedFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Create Unique Reference on SQL Column

Hi Guys

I have a Table called Person.

In Person I have  a column called UniqueRef.

The UniqueRef will start with LA00000001.

I need to create a sequential number.

So the next ref will be LA00000002 etc.

Thanks.
Avatar of Aneesh
Aneesh
Flag of Canada image

Why dont you create an identity column and display the column like this 'LA00000001'
ASKER CERTIFIED SOLUTION
Avatar of dsacker
dsacker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is this column the primary key? if so then go with anees's suggestion above and make it an identity column and just format the value as needed with something like:

   'LA' + RIGHT('00000000' + UniqueRef, 8)

If this is not the case then I would just include the logic for determine the value of UniqueRef in the procedure that should be handling your insertions in that table.