convert string to ascii values

  • Comments posted to this topic are about the item convert string to ascii values

  • Alternatively, using a Tally table (see link in my sig) to avoid the loop:

    declare @x nvarchar(100)

    set @x = 'AZ az' + char(160) + '01' -- note: 160 is an html non breaking space

    SELECT

    SUBSTRING(@x,N,1), ASCII(SUBSTRING(@x,N,1))

    FROM

    Tally

    WHERE

    N <= LEN(@x)

  • A very similar script is in BOL if you look up CHAR.

  • Cool. I did not know that, but I see it now. Usually when I look for code examples I don't search BOL, I search this site. If I don't find what I need, it's time to contribute code. Thanks.

  • Jon McGhee (4/30/2010)


    Cool. I did not know that, but I see it now. Usually when I look for code examples I don't search BOL, I search this site. If I don't find what I need, it's time to contribute code. Thanks.

    I have to ask then... do you know what a Tally table is and how it works to replace While Loops? And, no, I'm not trying to be a smart guy here.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • LondonNick (4/30/2010)


    A very similar script is in BOL if you look up CHAR.

    Agreed... and it shouldn't be used either. 😉

    For those that haven't seen it, please see the following for how a "Numbers" or "Tally" can be used as a very high performance replacement for certain types of While Loops...

    http://www.sqlservercentral.com/articles/T-SQL/62867/

    There are dozens of uses for such a table.

    I also agree with Jon... if you find something that may be useful, it's impossible to know if it posted somewhere else or even in BOL. Nothing wrong with posting something you may think is useful even if it's documented in BOL. After all, there are still a lot of folks that don't even know what BOL is never mind having actually read it from top to bottom.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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