Convert() Functionality -> MS webpage error?

  • 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

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • 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

    Bob
    -----------------------------------------------------------------------------
    How to post to get the best help[/url]

  • Ah. Thank you for pointing that out.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply