What is wrong with my query, conversion from binary version string.

  • Trying to get this query to work, converting a binary version string to human readable output but somehow it doesn't work, any ideas?

    😎

    /* Version number binary from daily registy */

    DECLARE @VERSION_STRING VARBINARY(16) = 0x4D5544532556564C5B504C552D675B;

    /* Inline Tally for parsing the binary string */

    ;WITH T(N) AS (SELECT N FROM (VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL)) AS X(N))

    ,NUMS(N) AS (SELECT TOP(DATALENGTH(@VERSION_STRING)) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS N FROM T T1,T T2)

    /* Human readable output */

    SELECT

    (

    SELECT

    CHAR(ASCII(SUBSTRING(@VERSION_STRING,NM.N,1)) - NM.N)

    FROM NUMS NM

    ORDER BY (NM.N % (DATALENGTH(@VERSION_STRING) / 4)) % (DATALENGTH(@VERSION_STRING) / 3)

    FOR XML PATH(''),TYPE

    ).value('.[1]','VARCHAR(24)') AS VERSION_NAME;

  • Very nice. Glad I tried running it before spending any time trying to break the query down.

  • HA! Very nice.

    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.

  • Yes it is nice.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Little bit of giggle but more like crypto 101 with some artificial complexity sprinkled on top;-)

    😎

  • Nice!

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 7 posts - 1 through 6 (of 6 total)

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