all groups > sql server programming > november 2003 >
You're in the

sql server programming

group:

Using TimeStamp column



Using TimeStamp column Vince Marciano
11/25/2003 9:29:47 PM
sql server programming: Hi,

I am passing an XML text stream into a stored procedure
which contains a timestamp field for me to use as the way
to handle concurrency. I can retrieve each of the elements
in the XML stream. My problem is the timestamp field comes
in as a character string e.g.
<row_timestamp>0x000000000000102B<\row_timestamp> and I
want to use this in my where clause to ensure that no one
else has updated the record since I retrieved it.

I need to be able to convert the row_timestamp in the XML
stream to a datatype of timestamp or be able to convert
the column in my table to a comparable datatype.

When I use cast(row_timestamp as char(18)) I get back
nothing for the value. If I use cast(cast(row_timestamp as
char(18)) AS binary(8)) I get back a value that is the
same to what is in the XML stream but of a different type
which are not comparable.

If I go the other way if I use:
CAST('0x000000000000102B' AS timestamp)
then I get the result: 0x3078303030303030 which is not the
same value.

Can someone please help me or comfirm that this is not
able to be done.

Regards,
Re: Using TimeStamp column Dan Guzman
11/26/2003 8:25:29 AM
There's an undocumented function to convert a binary value to a hex string:

SELECT master.dbo.fn_varbintohexstr(0x000000000000102B)

However, it's not a good idea to include undocumented features in production
code so I suggest you write your own function. You can reverse engineer
this system function if needed.

--
Hope this helps.

Dan Guzman
SQL Server MVP


[quoted text, click to view]

Re: Using TimeStamp column Vince Marciano
11/26/2003 4:01:06 PM
Thanks Dan this works great.

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button