2

I'd like to be able to append some data to a binary field in a MS SQL 2005 server from C# without reading the original data, concatenating it, and then setting it all back.

Is this possible?

Cheers! Steve

Steve
  • 4,859
  • 5
  • 21
  • 17

3 Answers3

2

I don't know if this option exists in MSSQL 2005, but if someone is searching for appending info into varbinary(max) in MSSQL2008 it can be done like this:

UPDATE [dbo].[Files] SET [FileContent].WRITE('0x',NULL,0)
WHERE Id = 1

Hope this will help someone.

Michal Krawiec
  • 375
  • 1
  • 2
  • 14
1

Read about the UPDATETEXT sql statement at http://msdn.microsoft.com/en-us/library/3517w44b.aspx. The Msdn article contains example code that appends binary data to a blob in the StorePhoto method.

sisve
  • 19,501
  • 3
  • 53
  • 95
  • Note that even though this is the accepted answer, if you come here via a search engine as I did, please be aware that it is no longer entirely the correct answer as the `UPDATETEXT` statement has been deprecated. (According to the docs "This feature will be removed in a future version of Microsoft SQL Server") Michal's answer below (to use `.WRITE`) is now the recommended approach and seems to be working fine from the limited testing I've just been doing. – Richard Moss Jul 08 '14 at 12:02
0

Well, I don't know for a BLOB, but for text you can do this:

UPDATE tablename SET columnname=concat(columnname,' my extra text');

Stormenet
  • 25,926
  • 9
  • 53
  • 65