I have a query which joins two tables based on a Timestamptimestamp
value (don't ask).
One of these tables stores the data in a column with a Timestamp
data type. The other stores it as a varcharvarchar
.
Previously, the query converted the timestamptimestamp
column to a varcharvarchar
for the join. As I understand it this is not sargable, so I'd like to do the reverse. (The "Timestamp"timestamp
table is much larger and efficiency is more of an issue).
SELECT *
FROM TABLE1
INNER JOIN TABLE2
ON UPPER(master.dbo.fn_sqlvarbasetostr(cast(TimestampColumn as binary(8))))
= VARCHARTIMESTAMPCOLUMN
I've tried:
CONVERT(ROWVERSION, N'0x0000000003306BDD')
No error, but no match on the table (when a row definitely exists).
CONVERT(ROWVERSION, CAST(N'0x0000000003306BDD' as bigint))
This gives an error converting nvarcharnvarchar
to bigintbigint
.
How can I convert the varcharvarchar
value into a timestamptimestamp
rather than the other way around?