declare @T table(SomeTimestampColumn timestamp, id int)
insert into @T(id) values(1)
insert into @T(id) values(2)
select
(select SomeTimestampColumn for xml path('')) as SomeTimestampColumn
from @T
Если вы хотите, чтобы столбец имел тип XML
select
(select SomeTimestampColumn for xml path(''), type) as SomeTimestampColumn
from @T
Или, если вам нужно только значение
select
T1.ID,
T3.N.value('.', 'varchar(50)') as SomeTimestampColumn
from @T as T1
cross apply
(select T1.SomeTimestampColumn for xml path(''), type) as T2(X)
cross apply
T2.X.nodes('SomeTimestampColumn') as T3(N)
Результат
ID SomeTimestampColumn
----------- --------------------------------------------------
1 AAAAAAACDZg=
2 AAAAAAACDZk=
Преобразование в Base64, и вы можете преобразовать его обратно. Вот ссылка на некоторые UDF, которые также могут выполнять преобразование. http://www.vbforums.com/showthread.php?t=554886
declare @T table(SomeTimestampColumn timestamp, id int)
insert into @T(id) values(1)
declare @Base64 varchar(max)
declare @Binary varbinary(max)
select
@Binary = T1.SomeTimestampColumn,
@Base64 = T3.N.value('.', 'varchar(50)')
from @T as T1
cross apply
(select T1.SomeTimestampColumn for xml path(''), type) as T2(X)
cross apply
T2.X.nodes('SomeTimestampColumn') as T3(N)
select
@Base64,
CAST(N'' AS XML).value('xs:base64Binary(xs:hexBinary(sql:variable("@Binary")))', 'VARCHAR(MAX)'),
@Binary,
CAST(N'' AS XML).value('xs:base64Binary(sql:variable("@Base64"))', 'VARBINARY(MAX)')
Результат:
AAAAAAAAJ3k= AAAAAAAAJ3k= 0x0000000000002779 0x0000000000002779