SQL problem: Converting timestamp field into double value
I'm writing a VB app which sends an SQL statement to MS SQL Server:
strSQL = "select * from systemevents where timestamp >= " + CStr(LastEventTimestampRead) + " ORDER BY timestamp"
strSQL = the SQL statement
timestamp = field with date and time value, in date and time format.
LastEventTimestampRead = double variable from external source, representing a time value.
How do I convert the timestamp field value into a DOUBLE type value within the SQL statement, so I can compare it with the LastEventTimestampRead variable? I tried CDbl but that's an Access command that's not compatible with SQL Server.
Thanks.
Re: SQL problem: Converting timestamp field into double value
Is the datatype of your TimeStamp column datetime, smalldatetime or timestamp?
TimeStamp columns have nothing to do with date and/or time. It is an 8 byte binary value generated by sql server. You should only be checking for equality with timestamp columns. Also, I believe it is impossible to pass timestamp values between SQL Server and VB via strings. Use the ADO Command object with a Parameter instead.
If your timestamp column is datetime or smalldatetime, there is no reason to convert it to double.
VB Code:
strSQL = "select * from systemevents where timestamp >= '" & Format$(LastEventTimestampRead,"yyyymmdd") & "' ORDER BY timestamp"