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 2005 Forums
 Transact-SQL (2005)
 Current Time

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-02-05 : 10:51:29
Hello,

When I have a table where one of the fields is the current time what should I do:

1. Make my SQL procedure insert the current time?
How is this done?
2. Send the current time from my .NET code adding a parameter in my SQL procedure?

Thanks,
Miguel

Kristen
Test

22859 Posts

Posted - 2007-02-05 : 10:57:57
I wouldn't send the time from your application. Your application might be running in a different time zone to the SQL Server (or even in multiple timezones). I would suggest you use SQL Server's time.

Yes your SQL Procedure can insert the time, or (I think probably better) you could set the column to DEFAULT to current time, and not insert that column at all (assuming you ONLY want the time set when you INSERT a new row - if you want it also set whenever you UPDATE the row then either a) make sure ALL the processes that update the row set the current time, or b) use a Trigger to ensure that it is ALWAYS set)

Kristen
Go to Top of Page
   

- Advertisement -