|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
automatically generated number but with prefix
hey all,
I've posted about this before so apologies to anyone who read it the first time. I want to have an ID column in my table, but I want the automatically generated number to have a prefix such as ABC. I'd also like to be able to change this prefix from an asp page depending on what is selected from a drop down. Is any of this possible? I'd really appreciate a reply, even if it's to say this can't be done. Thanks ![]() |
|
#2
|
|||
|
|||
|
What about having 2 columns, one with the automatically generated number (an Identity column) and one that contains the prefix and the number?? I don't think the other set-up is possible. MyTable has columns: IdentityColumn, PreFixedColumn and col1, col2, col3, etc.
SET NOCOUNT ON; DECLARE @MyIdentity int; INSERT INTO MyTable (col1, col2, col3) VALUES (value1, value2, value2); SELECT @MyIdentity = @@IDENTITY; UPDATE MyTable SET PrefixedColumn = 'ABC' + @MyIdentity WHERE IdentityColumn = @MyIdentity; ..or you can use a trigger! |
|
#3
|
|||
|
|||
|
Thanks, I'll give that a go
![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > automatically generated number but with prefix |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|