Search code examples
sqlsql-serverssms

How can I remove the first byte multiple rows of varbinary data?


I reworked a VB script to log parts over a final operation at work, but it added an additional byte at the beginning I would like to remove.

Test table, need to remove the first two zeros

This is the format of the table


Solution

  • SQL substring() (and likely some other string functions) work on binary types too. Something like this could work:

    update yourtable 
    set data = substring(data, 2, len(data)) 
    where substring(data, 1, 1) = char(0).
    

    I'm not sure about where conditon - you need to try yourself.