I have a DateTime column in my table, and I want to select the first couple of rows whose DateTime values are closest to the currect serve rdatetime. Is there a function like Max() that I can use?
Also, quesion about timestamp. If I create a column of type timestamp, is the value automatically entered by the database on every insert entry to the table?
I have had problems using timestamp so I switched to using datetime now.
Help appreciated!For the first part of your question, I would use the DATEDIFF() function to find the difference between the current date (GETDATE()) and the date value stored in your column, sorted in DESC order, taking the TOP 1 or 2 (however many you want).
The Timestamp data type is actually a unique rowversion containing binary/varbinary data, and its value only has meaning to SQL Server itself. SQL Server updates the value in this column upon every INSERT, UPDATE, and DELETE. You could make use of this Timestamp value for concurrency control, but it does not contain datetime data -- it contains binary/varbinary data.
Terri
No comments:
Post a Comment