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)
 Internal clock times and datediff query

Author  Topic 

sqlnovice1
Starting Member

34 Posts

Posted - 2011-08-19 : 07:29:59
Hi

i have to generate a key in a table by way of concatination.

exmaple key : CLINC:CONS:09/09/2010:CRN:15:30:00

the problem i have is that i wish to show the time as the internal clock formats, in seconds past midnight so would expect to see ......

exmaple key : CLINC:CONS:09/09/2010:CRN:38700

Does anyone have any ideas????

Thanks in advance

Paul

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-19 : 07:33:17
yep. just do like

DATEDIFF(ss,DATEADD(dd,DATEDIFF(dd,0,datecol),0),datecol)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sqlnovice1
Starting Member

34 Posts

Posted - 2011-08-19 : 09:55:23
Many Thanks. All sorted now.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-19 : 10:52:26
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-08-19 : 14:15:26
IMO - that key doesn't look very reliable for uniqueness. Even if you included down to the milliseconds I would expect an eventual collision. If there is no natural key in the table then how about an int identity surrogate?

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -