Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6083967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:27:56+00:00 2026-05-23T11:27:56+00:00

Using SQL Server 2008+. I have a rowversion column (aka timestamp) which I retrieve

  • 0

Using SQL Server 2008+.

I have a rowversion column (aka timestamp) which I retrieve from the database and convert into into a numeric(20,0) using the following code:

CONVERT(NUMERIC(20,0), RowVersionColumn + 0) AS [RowVersion]    

Later on, I need to take that numeric value (which is stored in a ADO.NET DataSet as a ulong/UInt64), and convert it back into a rowversion data type.

This creates problems, though. It seems as though while you can convert out to numeric(20,0), the reverse operation fails to yield the correct value. For instance:

DECLARE @MyNumericValue NUMERIC(20,0)
DECLARE @MyRowVersionValue ROWVERSION

SET @MyNumericValue = 12345
SET @MyRowVersionValue = CONVERT(rowversion, @MyNumericValue)

PRINT CONVERT(NUMERIC(20,0), @MyRowVersionValue + 0)

Running this code prints out a value of 959447040, not 12345. Removing the “+ 0” from the CONVERT statement yeilds the correct result, but I’m still unable to reliably take a numeric value that used to be a rowversion and turn it back into a rowversion whose value is what it should be.

Below is an even better demonstration of this issue:

DECLARE @MyNumericValue NUMERIC(20,0)
DECLARE @MyRowVersionValue ROWVERSION
DECLARE @MyRowVersionValue2 ROWVERSION

SET @MyRowVersionValue = @@DBTS
SET @MyNumericValue = CONVERT(NUMERIC(20,0), @MyRowVersionValue + 0)
SET @MyRowVersionValue2 = CONVERT(rowversion, @MyNumericValue)

SELECT @MyRowVersionValue 
SELECT @MyNumericValue
SELECT @MyRowVersionValue2

Your results will vary depending on your inputs, but as an example my output was:

0x0000000003ADBB2F
61717295
0x140000012FBBAD03

The first and last values should match, but they don’t. I’m guessing this has something to do with the fact that binary data conversions often result in padding, and this padding changes the value. See:

http://msdn.microsoft.com/en-us/library/aa223991(v=SQL.80).aspx

Thoughts?

EDIT: To clarify, the fact I’m dealing with rowversion/timestamp is incidental. This same issue happens with BINARY(8) instead of ROWVERSION, as they’re equivalent data types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:27:56+00:00Added an answer on May 23, 2026 at 11:27 am

    While I don’t understand why you would be converting a meaningless ROWVERSION value to a number and then back again, did you try with BIGINT – which matches the 8 bytes required by UInt64 and not the variable number of bytes (depending on the actual value) that forcing NUMERIC(20,0) would change it to?

    CREATE TABLE dbo.rv(a INT, rv ROWVERSION);
    
    INSERT dbo.rv(a) SELECT 1 UNION SELECT 2;
    
    WITH x AS
    (
        SELECT 
            rv, 
            rv_as_bigint = CONVERT(BIGINT, rv) 
        FROM dbo.rv
    )
    SELECT 
        rv, 
        rv_as_bigint, 
        rv_back_to_rv = CONVERT(ROWVERSION, rv_as_bigint) 
    FROM x;
    
    DROP TABLE dbo.rv;
    

    Or taking your original sample and just swapping BIGINT in for NUMERIC(20,0):

    DECLARE @MyNumericValue BIGINT
    DECLARE @MyRowVersionValue ROWVERSION
    DECLARE @MyRowVersionValue2 ROWVERSION
    
    SET @MyRowVersionValue = @@DBTS
    SET @MyNumericValue = CONVERT(BIGINT, @MyRowVersionValue) -- removed the +0 hack
    SET @MyRowVersionValue2 = CONVERT(rowversion, @MyNumericValue)
    
    SELECT @MyRowVersionValue 
    SELECT @MyNumericValue
    SELECT @MyRowVersionValue2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that I have created using SQL Server Developer 2008. I
Using SQL Server 2008. I have a table variable with a single column and
I am using SQL Server 2008. I have a Student table in which there
We are using SQL Server 2008. We have a table called response which has
I am using SQL Server 2008. I have tables on which there are duplicate
I'm using SQL Server 2008. I have a database table that looks like this
I have Database table and I am using SQL Server 2008. The table contins
I am using SQL Server 2008 and I have a database file (mydata.mdf) in
I am using SQL Server 2008 Enterprise. I have yearly customer data from 2000
I am using SQL Server 2008 R2. I have imported 2 tables from excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.