Removing padded zeroes in Hexadecimal column

2019-08-02 09:11发布

问题:

I have a database in TSQL that contains columns in hexadecimal. However these values are padded with zeroes to fill the column.

I need to remove these zeroes just so I have the hexadecimal string. The problem is I cannot just remove pairs of zeroes as the string may have zeroes in the middle.

I have a feeling I need to convert it to say decimal and then back or something, but everything I try yields strange results.

The column in the database look like this:

1EBC67E6000000
6B1FE9C7830000
C700DBBF000000

The values are different lengths and all padded with pairs of zeroes.

Any ideas would be good!

回答1:

Maybe this will be good for you:

Select  replace(rtrim(replace('C700DBBF000000','0',' ')),' ','0');


标签: sql tsql hex