SQL SERVER ASCII String FUNCTION
ASCII function returns int value of first character in the String
for ex: select ASCII('America') gives 65 i.e ASCII value of A.
select ASCII('american') gives 97 i.e ASCII value of small a.
Suppose u want to display ASCII values of all characters in the string along with character value.
Here is the Procedure.
declare @position int,@ttx nchar(25)
set @position=1;
set @ttx='America!';
set nocount off;
while @position <= LEN(@ttx)
begin
select ascii(substring(@ttx,@position,1)) as ASCII,CHAR(ascii(substring(@ttx,@position,1))) as CHAR;
set @position = @position + 1;
end
set @position=1;
set @ttx='America!';
set nocount off;
while @position <= LEN(@ttx)
begin
select ascii(substring(@ttx,@position,1)) as ASCII,CHAR(ascii(substring(@ttx,@position,1))) as CHAR;
set @position = @position + 1;
end
O/P:
ASCII CHAR
65 A
65 A
ASCII CHAR
109 m
109 m
ASCII CHAR
101 e
101 e
ASCII CHAR
114 r
114 r
ASCII CHAR
105 i
105 i
ASCII CHAR
99 c
99 c
ASCII CHAR
97 a
97 a
ASCII CHAR
33 !
33 !
tags:SQL Server ASCII String function,SQL Server ASCII function,return ASCII value of String in SQL-Server
No comments:
Post a Comment