Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prefix to autonumber

Status
Not open for further replies.

johnc83

Technical User
Jan 29, 2008
154
0
0
GB
Hi all,

can someone tell me how to add a prefix to an autonumber column in SQL server 2005 Express pls.

At the moment it gives next job number as 1, 2, 3 etc.. but I need it to go RE1, RE2, RE3...

Any help would be greatly appreciated.

Cheers

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
My suggestion would be to create a computed column that concatenates RE with your identity column. Identity columns must be an integer, however, by creating a computed column, you get the best of both worlds. You get a column that appears to be an autonumber with a prefix without having to maintain it yourself.

To add a computed column to a table...

[tt][blue]Alter Table [!]TableName[/!] Add [!]ColumnName[/!] As 'RE' + Convert(VarChar(20), [!]IdentityColumnName[/!])[/blue][/tt]



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
awesome, thank you very much!

John

.NET 2.0, Visual Studio 2005, SQL Server 2005 Express
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top