Marian Zagoruiko
Marian Zagoruiko

Reputation: 1596

varbinary and FOR XML clause

How can I store a value returned by COLUMNS_UPDATED() in the xml message? I wanna later get it back to the varbinary(max) variable and perform some operations.

Upvotes: 0

Views: 1326

Answers (1)

Remus Rusanu
Remus Rusanu

Reputation: 294467

Adding a varbinary value into an XML type stores it as base64 encoded, and extracting the value already knows how to decode it:

declare @v varbinary(1000) = 0x0102030405;
declare @x xml;
set @x = (select @v as value for xml path ('message'), type);
select @x, @x.value(N'(/message/value)[1]', N'varbinary(1000)');

Upvotes: 2

Related Questions