SunQuest
           MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 23rd, 2004, 09:46 AM
sql asp sql asp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: UK
Posts: 259 sql asp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 51 sec
Reputation Power: 4
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

Reply With Quote
  #2  
Old August 23rd, 2004, 01:54 PM
PrivateJson PrivateJson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Denmark
Posts: 24 PrivateJson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 4 sec
Reputation Power: 0
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!

Reply With Quote
  #3  
Old August 24th, 2004, 03:22 AM
sql asp sql asp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: UK
Posts: 259 sql asp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 51 sec
Reputation Power: 4
Thanks, I'll give that a go

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > automatically generated number but with prefix


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway