Here’s a simple query that lists the ASCII Value of each character in your string in SQL Server
DECLARE @counter int = 1;
DECLARE @colString varchar(10) = 'AA%#& ';
WHILE @counter <= DATALENGTH(@colString)
SELECT CHAR(ASCII(SUBSTRING(@colString, @counter, 1))) as [Character],
ASCII(SUBSTRING(@colString, @counter, 1)) as [ASCIIValue]
SET @counter = @counter + 1
Here we are using the ASCII function to list the ASCII values of each character
This function can be very useful to find and replace characters like Tabs, LineFeed etc. that may get inserted in a string. Check the last row in the screenshot above. It is the Tab Control Character with ASCII 9.
In case you want to remove the Tab Character, use this query
SET @colString = REPLACE(@colString, CHAR(9), '')
Did you like this post?
|subscribe via rss||subscribe via e-mail|
|print this post||follow me on twitter|