Please visit DEMANDDRAFT.SHOP for quality of products...

Ad

Search This Blog

Tuesday, July 17, 2012

ASCII() String Function in SQL Server

ASCII()
Returns the ASCII code value of the leftmost character of a character expression.

Syntax
 ASCII ( character_expression )


Example: 
SELECT ASCII('A') 

SET TEXTSIZE 0

SET NOCOUNT ON

-- Create the variables for the current character string position
-- and for the character string.

DECLARE @position int, @string char(15)

-- Initialize the variables.
SET @position = 1
SET @string = 'The codeProject'

WHILE @position <= DATALENGTH(@string)
   BEGIN
   SELECT ASCII(SUBSTRING(@string, @position, 1)),
      CHAR(ASCII(SUBSTRING(@string, @position, 1)))
    SET @position = @position + 1
   END

SET NOCOUNT OFF

 
Output:
-----------
65
----------- ----
84          T
----------- ----
104         h
----------- ----
101         e
----------- ----
and so on.....
 

No comments:

Post a Comment