The following four kinds of 99 multiplication tables of SQL statements written with the while and if conditions
SQL statement implementation--x lower left corner 99 multiplication table
DECLARE @i INT, @j int,@s VARCHAR ()
set @i= while
@i<
BEGIN
set @j=
set @s= ' while
@j<=@i
BEGIN
Set @s=@s+cast (@j as char ()) + ' * ' +cast (@i as char ()) + ' = ' +cast ((@i*@j) as char ())
set @j=@j+
end
PRINT @s< C14/>set @i=@i+ End
Results:
SQL statement implementation--x right lower corner 99 multiplication table
DECLARE @i INT, @j int,@s VARCHAR ()
set @i= while
@i<
BEGIN
set @j=
set @s= ' while
@j& gt;
Begin
IF @j>@i
begin
Set @s=@s+ ' --seven space end
ELSE
begin
Set @s=@s+cast (@i as char ()) + ' * ' +cast (@j as char ()) + ' = ' +cast ((@i*@j) as char ())
end
SET @j=@j-
end
PRINT @S
SET @i=@i+
End
Results:
SQL statement Implementation--9x9 upper right corner
DECLARE @i INT, @j int,@s VARCHAR (m)
set @i=1 while
@i<10
BEGIN
set @j=1
set @s= "while
@j <10
begin
IF @j<@i
begin
Set @s=@s+ ' --7 end
ELSE
begin
Set @s= @s+cast (@i as char (1)) + ' * ' +cast (@j as char (1)) + ' = ' +cast ((@i*@j) as char (3))
end
SET @j=@j+1 end
PRINT @S
SET @i=@i+1
End
Results:
SQL statement implementation--9x9 Upper left corner
DECLARE @i INT, @j int,@s VARCHAR (m)
set @i=1 while
@i<10
BEGIN
set @j=@i
set @s= '
While @j<10
BEGIN
SET @s=@s+cast (@i as char (1)) + ' * ' +cast (@j as char (1)) + ' = ' +cast ((@i*@j) as char (3))
SET @j=@j+1
End
PRINT @S
SET @i=@i+1
End
Results:
The above content is through four ways to write 99 multiplication table, I hope you like.