472,110 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Best method for storing a time in a MsSQL database?

113 100+
Hi,

I've recently been porting a little php / mysql script over to asp / mssql and I've got issues with the timestamp data type. With mysql i could easily insert 01:01:01 into the timestamp column, however mssql throws an error and whats the string passed in to be converted into a timestamp data type.

Is this the right datatype to use? I read somewhere that the timestamp column is readonly and is updated each time the record is updated, if this is the case then i shouldn't be using the timestamp column. But then I'm posed with the problem that when I select and display the records how do i sort them by the lowest time?

I'm creating a a highscores table, the lowest time being the highest score.

Here is my current mssqyl statement:
Expand|Select|Wrap|Line Numbers
  1.         sqlStatement = "INSERT INTO scores (name,email,usertime,milliseconds) VALUES('" & fName & "','" & fEmail & "',CAST('" & fTime & "' as timestamp),'" & fMilliseconds & "')"
  2.  
error:
Expand|Select|Wrap|Line Numbers
  1. Cannot insert a non-null value into a timestamp column. Use INSERT with a column list or with a default of NULL for the timestamp column.
  2.  
Thanks!
Aug 22 '08 #1
0 1000

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by Joshua Beall | last post: by
6 posts views Thread by Tippy G | last post: by
5 posts views Thread by Andrew S. Giles | last post: by
reply views Thread by Anonieko Ramos | last post: by
9 posts views Thread by Luke Vogel | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.