Using SQL Server Timestamp

Well, I googled using timestamp and sql server and while there was some good advice out there, I never saw an example of how to send that value back to sql and compare it.  All the examples showed how to pull it from the database and talked about the necessity of it when wanting to make sure there was no accidental overwrites, etc.

I am here to change that. It seems that the sql server timestamp type can be easily converted into a bigint and vice versa. This simplified a lot of items for me and made the timestamps very human readable.

Any how here is the code snippets:

SQL  Server Get Code:

SELECT CAST(a.RowTimestamp AS BIGINT) AS RowTimestamp, ...

 

SQL  Server Update Code:

WHERE   RowTimestamp = CAST(@RowTimestamp AS TIMESTAMP)

 

.NET Property

Private  _RowTimestamp as Int64
....
  Public Property RowTimestamp() As Int64
            Get
                Return _RowTimestamp
            End Get
            Set(ByVal value As Int64)
                _RowTimestamp = value
            End Set
        End Property

 

.NET Data Access Read

myClass.RowTimestamp = sqlDR.GetInt64(i)

 

I hope this helps you as it did me.

Robert Wallace
No Slogans, Just Results

Advertisements

About RWallace Consulting, LLC

Since 2002, RWallace Consulting, LLC has been developing software across a myriad of industries. Right now, we specialize in Microsoft .NET technologies.
This entry was posted in SQL Server, Timestamp and tagged , , . Bookmark the permalink.

3 Responses to Using SQL Server Timestamp

  1. shawn says:

    I wish i had come to your site eariler. I came to the same conclusion, but you’ ve been helpful in confirming this. thanks.

  2. sarathrap says:

    Hi Wallace,

    I am facing an issue in casting this Timestamp to Bigint. like this
    set NodeID = cast(RowID(its a timestamp) as bigint). But the problem here is it is generating a value of length 9 characters which was not the case in prior. Every time I am truncating the table before updating like this. But it is used to generate only a numeric value of length 8 only and which is same I am sending it some other down stream application. And they also will accept only the value with length 8. So could you please help me out fixing this issue.

    Thanks,
    Sarath.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s