Avatar of Morpheus7
Morpheus7
 asked on

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
Microsoft SQL ServerMicrosoft SQL Server 2005SQL

Avatar of undefined
Last Comment
Raja Jegan R

8/22/2022 - Mon
Scott Pletcher

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)
ASKER CERTIFIED SOLUTION
Raja Jegan R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck