News

Copyright © 2008-2018 Paula DiTallo

Tag Cloud



SQL Server: How do I pull the ASCII value for each character in a column name?

This is a handy script to cycle through every character in a column to determine what each ascii value is.  This is especially useful when a string match isn't matching.  Often times, there is a hidden space, etc.

 DECLARE @counter int = 1;
--DECLARE @asciiString varchar(10) = 'AA%#&    ';
 DECLARE @asciiString varchar(100) 
 
 SELECT @asciiString = [ColumnName]
  FROM schema.TableName
  where ColumnName like '%Something%'

WHILE @counter <= DATALENGTH(@asciiString)
   BEGIN
   SELECT CHAR(ASCII(SUBSTRING(@asciiString, @counter, 1))) as [Character],
   ASCII(SUBSTRING(@asciiString, @counter, 1)) as [ASCIIValue]
     
   SET @counter = @counter + 1
   END
GO
Tuesday, February 27, 2018 5:22 PM

Feedback

# re: SQL Server: How do I pull the ASCII value for each character in a column name?

Can't the first line of that query be reduced to just :

SELECT SUBSTRING(@asciiString, @counter, 1) as [Character],
2/28/2018 11:57 AM | James M. Curran

Post A Comment
Title:
Name:
Email:
Comment:
Verification: