Sql server 编写99乘法表

Sql 组织编写语句

declare @one int,@tow int,@str varchar(100),@num int
select @one=1
while(@one<=9)
begin
select @tow=1,@str=''
      while(@tow<=@one)
      begin
        set @num =@tow*@one   --求积
        set @str+='  '+convert(varchar,@tow)+'*'+convert(varchar,@one)+'='+convert(varchar,@num)  --拼接字符串
        set @tow=@tow+1
      end
          print @str    
  set @one=@one+1
end

 

结果样式:

 

posted @ 2018-03-30 15:48  刘靖凯  阅读(662)  评论(0编辑  收藏  举报