日期:2014-05-17 浏览次数:20549 次
declare @val varchar(20)='i am student'
declare @wz int=1
declare @a char(1)
while @wz<LEN(@val)
begin
set @a=SUBSTRING(@val,@wz,1)
if @a<>''
begin
select @a,ascii(@a)
end
set @wz=@wz+1
end
DECLARE @position int, @string char(15)
-- Initialize the variables.
SET @position = 1
SET @string = 'i am student'
WHILE @position <= DATALENGTH(@string)
BEGIN
SELECT ASCII(SUBSTRING(@string, @position, 1)),
CHAR(ASCII(SUBSTRING(@string, @position, 1)))
SET @position = @position + 1
END