Convert rowversion to varchar in SQL Server 2005

Hi,

I need to be able to compare Rowversion to be able to detect data changes for an ETL process. I am using SQL Server 2005. The process needs to convert to varchar for comparison. I have trawled the net for some suggestions but I think there is a problem with case sensitivity:

When I run select min_active_rowversion() this is retuned - 0x0000000002514EB9

When I run SELECT sys.fn_sqlvarbasetostr(min_active_rowversion())
or
SELECT master.dbo.fn_varbintohexstr(min_active_rowversion())
0x0000000002514eb9 is returned which is a different value to that returned by min_active_rowversion()

Is there a process that I can use to be able to return the value of min_active_rowversion() as a varchar?

Many thanks
Morpheus7Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
I would think you could cast it to a bigint, and then cast the bigint to char(19+)/varchar(19+).

And vice-versa to reconvert.

For example:

declare @rowversion rowversion
set @rowversion = 0x0000000002514EB9

select cast(cast(@rowversion as bigint) as varchar(19))
select cast(cast(cast(cast(@rowversion as bigint) as varchar(19)) as bigint) as rowversion)
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
>> Is there a process that I can use to be able to return the value of min_active_rowversion() as a varchar?

Wondering why you wish to convert it to a varchar for comparison when it can be directly compared out with other rowversion values like this..
By default, with rowversion column, we can do equal to , not equal to, greater than, less than, MIN, MAX operations..
Please find the examples for the same and let us know whether you can use these to get your requirement work or not..
create table test ( a int, b rowversion)

insert into test (a) values(1)
insert into test (a) values(2)
insert into test (a) values(3)
insert into test (a) values(1)
insert into test (a) values(2)
insert into test (a) values(3)

select * from test

select * 
from test t1 
join test t2 on t1.a = t2.a
where t1.b <> t2.b

select min(b), max(b), count(b)
from test 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.