The following four kinds of 99 multiplication tables for SQL statements written with the while and if conditions
1 --9x9 lower left corner2 3 DECLARE @i INT,@J INT,@S VARCHAR( -)4 SET @i=15 while @i<Ten6 BEGIN7 SET @J=18 SET @S="'9 while @J<=@iTen BEGIN One SET @S=@S+CAST(@J as CHAR(1))+'*'+CAST(@i as CHAR(1))+'='+CAST((@i*@J) as CHAR(3)) A SET @J=@J+1 - END - PRINT @S the SET @i=@i+1 - END
Results:
1 --9X9 lower right corner2 DECLARE @i INT,@J INT,@S VARCHAR( -)3 SET @i=14 while @i<Ten5 BEGIN6 SET @J=97 SET @S="'8 while @J>09 BEGINTen IF @J>@i One BEGIN A SET @S=@S+' '--Seven spaces - END - ELSE the 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 A END
Results:
--9x9 upper right cornerDECLARE @i INT,@J INT,@S VARCHAR( -)SET @i=1 while @i<TenBEGIN SET @J=1SET @S="' while @J<TenBEGIN IF @J<@iBEGINSET @S=@S+' '--7ENDELSE BEGIN SET @S=@S+CAST(@i as CHAR(1))+'*'+CAST(@J as CHAR(1))+'='+CAST((@i*@J) as CHAR(3))ENDSET @J=@J+1ENDPRINT @SSET @i=@i+1END
Results:
--9x9 Upper left cornerDECLARE @i INT,@J INT,@S VARCHAR( -)SET @i=1 while @i<TenBEGINSET @J=@iSET @S="' while @J<TenBEGIN SET @S=@S+CAST(@i as CHAR(1))+'*'+CAST(@J as CHAR(1))+'='+CAST((@i*@J) as CHAR(3))SET @J=@J+1ENDPRINT @SSET @i=@i+1END
Results:
SQL statements various 99 multiplication tables