• Eirikur Eiriksson (4/29/2014)


    Sean Lange (4/29/2014)


    What I don't really understand here is what is the point of this? This data is pretty much unusable because you have no way of putting it back together again.

    Probably a string of hex values would be better, at least every character representation is then of the same length.

    😎

    DECLARE @STRINGS TABLE

    (

    MYID INT IDENTITY(1,1) NOT NULL

    ,MYSTRING CHAR(5) NOT NULL

    )

    INSERT INTO @STRINGS (MYSTRING)

    SELECT MYSTRING FROM

    (VALUES ('02yC'),('12G8'),('9Pp1'),('7@uL')) AS X(MYSTRING);

    SELECT

    MS.MYID

    ,MS.MYSTRING

    ,SUBSTRING(CONVERT(VARCHAR(10),CAST(MS.MYSTRING AS VARBINARY(10)),1),3,10)

    FROM @STRINGS MS

    Results

    MYID MYSTRING HEX_STRING

    ----------- -------- ----------

    1 02yC 30327943

    2 12G8 31324738

    3 9Pp1 39507031

    4 7@uL 3740754C

    At you can put it back together. Still seems like far more effort than it is worth. We have effectively doubled the length of the string so we have to push twice as much data around. Ugh!!!

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/