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)
 TSQL Equivalent to Vb.net

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-11-04 : 21:55:15
hi

I am trying to generate an id by way using datetime. An example of an ID: 2009110510464946

This is how i use it to generate this ID using VB.Net:

Label1.Text = Now.ToString("yyyy/MM/dd").Replace("/", "") & Now.ToString("HH:mm:ss:mmm").Replace(":", "")

I tried using datepart but am not able to get that 16 digits value.

How should i go about it? Thanks

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-11-04 : 22:06:10
hi

I managed to solved it. Thanks

Replace(replace(Replace(replace(CONVERT(Nvarchar(50),Getdate(),120),'-',''),' ' ,''),':',''),'.','')
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-11-04 : 22:17:18
Generating an ID based on the system time is not a good idea because it is too easy to have diffrent processes generate the same ID.

Use SQL Server's IDENTITY functionality to generate an ID that is unique.




CODO ERGO SUM
Go to Top of Page
   

- Advertisement -