Minipulating data strings

  • Hi

    I need to convert certain codes to text descriptions but the codes are all stored together in a text field for a record:

    data sample '6,16,26'

    I need a UDF which will translate the string:

    6 = Red

    16 = blue

    26 = green

    so the string will be changed to: 'red, blue, green'

    Kind Regards

    Bill Humphrey

  • Without address a "Why" a direct answer to your question is ...

    DECLARE @t TABLE (codeValue VARCHAR(256))

    INSERT @t

    SELECT '6,16,26,35' UNION ALL

    SELECT '6' UNION ALL

    SELECT '26,16'

    SELECT REPLACE(REPLACE(REPLACE(REPLACE(codeValue,'35','Magenta'),'26','Green'),'16','Blue'),'6','Red')

    FROM @t

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg

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

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