Conversions between binary and integer types  Converting image columns to binary types

Chapter 2: Transact-SQL Functions

Converting between binary and numeric or decimal types

In binary and varbinary data strings, the first two digits after “0x” represent the binary type: “00” represents a positive number and “01” represents a negative number. When you convert a binary or varbinary type to numeric or decimal, be sure to specify the “00” or “01” values after the “0x” digit; otherwise, the conversion will fail.

For example, here is how to convert the following binary data to numeric:

select convert(numeric
(38, 18),0x000000000000000006b14bd1e6eea0000000000000000000000000000000)
----------
123.456000

This example converts the same numeric data back to binary:

select convert(binary,convert(numeric(38, 18), 123.456))
-------------------------------------------------------------- 
0x000000000000000006b14bd1e6eea0000000000000000000000000000000




Copyright © 2005. Sybase Inc. All rights reserved. Converting image columns to binary types

View this book as PDF