SQL语句打印四个方向的9 9 乘法表

时间:2023-03-09 16:23:36
SQL语句打印四个方向的9 9 乘法表
declare @i int ,@j int  ,@s nvarchar(max)
set @i = 1
while @i <=9
begin
set @s = ' '
set @j = 1
while @j <=@i
begin
set @s += cast(@j as char(1)) + '*' + cast(@i as char(1))
set @s += ' '
set @j +=1
end
print @s
set @i += 1
end

  

declare @i int ,@j int  ,@s nvarchar(max)
set @i = 1
while @i <=9
begin
set @s = ''
set @j = 1
while @j <=9
begin
if @j >= @i
begin
set @s += cast(@i as char(1)) + '*' + cast(@j as char(1))
set @s += ' '
end
else
begin
set @s += ' '
end
set @j +=1
end
print @s
set @i += 1
end
declare @i int ,@j int  ,@s nvarchar(max)
set @i = 1
while @i <=9
begin
set @s = ''
set @j = 1
while @j <=@i
begin
if @j >= @i
begin
set @s += cast(@i as char(1)) + '*' + cast(@j as char(1))
set @s += ' '
end set @j +=1
end
print @s
set @i += 1
end
declare @i int ,@j int  ,@s nvarchar(max)
set @i = 1
while @i <=9
begin
set @s = ''
set @j = 1
while @j <=9
begin
if @j > 9 -@i
begin
set @s += cast(@i as char(1)) + '*' + cast((10 -@j) as char(1))
set @s += ' '
end
else
begin
set @s += ' '
end
set @j +=1
end
print @s
set @i += 1
end