Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

convert string to ascii values Expand / Collapse
Author
Message
Posted Monday, April 26, 2010 11:30 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, February 20, 2014 12:27 PM
Points: 83, Visits: 597
Comments posted to this topic are about the item convert string to ascii values
Post #910830
Posted Friday, April 30, 2010 3:20 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 5:17 AM
Points: 1,180, Visits: 2,672
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)



--
Nigel
Useful Links:
How to post data/code on a forum to get the best help
The "Numbers" or "Tally" Table - Jeff Moden

Post #913537
Posted Friday, April 30, 2010 4:15 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 17, 2014 5:44 AM
Points: 393, Visits: 516
A very similar script is in BOL if you look up CHAR.


Post #913557
Posted Friday, April 30, 2010 7:49 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, February 20, 2014 12:27 PM
Points: 83, Visits: 597
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.
Post #913706
Posted Saturday, May 1, 2010 5:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 11:08 PM
Points: 35,547, Visits: 32,135
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #914281
Posted Saturday, May 1, 2010 5:07 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 11:08 PM
Points: 35,547, Visits: 32,135
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #914282
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse