Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating Id like P001,P002

Author  Topic 

kneel
Starting Member

36 Posts

Posted - 2008-09-24 : 07:55:26
Hello All,

How can I write insert query/sp to add profile id like P001,P002 dynamically into table which will be primary key in SQL server 2000.

if anyone has an idea, please let me know.

Thanks in advance.


--kneel

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-24 : 07:57:28
how many values you need to insert at a time? what determines number of values to be inserted?
Go to Top of Page

kneel
Starting Member

36 Posts

Posted - 2008-09-24 : 08:04:25
one only

--kneel
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-24 : 08:10:29
quote:
Originally posted by kneel

one only

--kneel


then just use

INSERT INTO Table (ProfileID,fields,...)
SELECT 'P001',...
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-09-24 : 08:41:53
Easier way is to create an Identity column, and then have a calculated column that concatenates it with your prefix.

Boycotted Beijing Olympics 2008
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-09-24 : 08:59:07
We have a whole article on this:

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

blindman's got the right idea ...

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -