Convert rowversion to varchar in SQL Server 2005

Morpheus7
Morpheus7 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott PletcherSenior DBA
Most Valuable Expert 2018
Top Expert 2014

Commented:
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)
SQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018
Commented:
>> 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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial