日期:2014-05-17  浏览次数:20497 次

用T_SQL语句编程求助啊
用T_SQL求“I am student.”中各字母的ASCⅡ码。(SQL2000)
菜鸟才学T_SQL啊。。求大神指点啊。。。
SQL 编程

------解决方案--------------------

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