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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Autogenerate "ORDERID"

Author  Topic 

jscot
Posting Yak Master

106 Posts

Posted - 2010-10-19 : 23:28:02
I have a field called "OrderID" i want this field auto generate"Unique" let say "COV-YYMMDDSS" so every time ORderid create it should be unique. Please send me t-sql code. Thanks in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-19 : 23:37:36
Is performance a concern? Why can't you use an identity column or a GUID?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jscot
Posting Yak Master

106 Posts

Posted - 2010-10-19 : 23:51:57
Table is already created and i can't change table structure. and requirement is use "ORderID" as a unique and auto generate.
Go to Top of Page

jscot
Posting Yak Master

106 Posts

Posted - 2010-10-19 : 23:52:35
Performance no concern, no issue!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-19 : 23:52:58
What does COV represent?

To get YYMMDDSS, use CONVERT function with the appropriate style (see CONVERT function in BOL).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-10-20 : 01:53:32
I hope you don't ever have more than one row inserted in a second, or that will no longer be unique.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

jscot
Posting Yak Master

106 Posts

Posted - 2010-10-20 : 08:56:25
COV Stand company name, It could be anything ABC-101020(SS) IF SECOND giving any problem then ABC-1010201,ABC-1010202,ABC-1010203 AND SO ON. Please any 1 paste a code for me, Thanks.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-10-20 : 09:59:48
There are several things wrong with your plan.

First, the two digit year limits the system to a lifetime of 10 years.

Second, the two digit second limits your system to a maximum of 99 orders per day.



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -