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.
| Author |
Topic |
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2009-11-04 : 21:55:15
|
| hiI am trying to generate an id by way using datetime. An example of an ID: 2009110510464946This 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
|
| hiI managed to solved it. ThanksReplace(replace(Replace(replace(CONVERT(Nvarchar(50),Getdate(),120),'-',''),' ' ,''),':',''),'.','') |
 |
|
|
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 |
 |
|
|
|
|
|