July 27, 2011 at 11:26 am
Am I reading this wrong? (See the underlined text & code):
Styles 1 and 2 introduce new functionality. These styles convert a hex string literal to a binary value that contains the same digits when presented in hex form and vice versa. If you use Style 1 when converting from a character string to a binary value, the input character string should include the 0x prefix; if you use Style 2, it should not. Similarly, if you use Style 1 when converting from a binary value to a character string, the output character string will contain the 0x prefix; if you use Style 2, it will not. The following example demonstrates using styles 1 and 2:
SELECT
CONVERT(VARCHAR(12) , 0x49747A696B , 1) AS [Bin to Char 1],
CONVERT(VARBINARY(5), '0x49747A696B', 1) AS [Char to Bin 1],
CONVERT(VARCHAR(12) , 0x49747A696B , 2) AS [Bin to Char 2],
CONVERT(VARBINARY(5), '49747A696B' , 2) AS [Char to Bin 2];
This code produces the following output:
Bin to Char 1 Char to Bin 1 Bin to Char 2 Char to Bin 2
------------- ------------- ------------- -------------
0x49747A696B 0x49747A696B 49747A696B 0x49747A696B
When I test this, I get the exact same results as above. But the last result is a character string going to Binary using Style 2, and it has an 0x prefix, when the text appears to say that it won't.
Is this an error with the text on the webpage or is it an error with the code? Or am I just misreading this?
Webpage is: http://technet.microsoft.com/en-us/library/cc721270(SQL.100).aspx
July 27, 2011 at 12:05 pm
If you use Style 1 when converting from a character string to a binary value, the input character string should include the 0x prefix; if you use Style 2, it should not.
The line says the input character should not have 0x not that the result will not have 0x
July 27, 2011 at 12:07 pm
Ah. Thank you for pointing that out.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply