Abdullah Zaid
Abdullah Zaid

Reputation: 181

Append binary using update in sql server

I have binary data in specific field in sql server 2008, but i want to append some binary data to the same field. can you help me about that?

Upvotes: 5

Views: 2825

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062965

If it is a varbinary(n) / varbinary(max) - you just append with +:

declare @foo table(id int, bar varbinary(max))

insert @foo values(1, 0x01)

declare @newdata varbinary(max) = 0x020304

update @foo set bar = bar + @newdata
where id = 1

select bar from @foo
where id = 1

If you are using image, you can use UPDATETEXT, but it is more involved (read MSDN) - insert_offset of NULL means "append", and specify delete_length of 0.

Upvotes: 8

Related Questions