The following four kinds of 99 multiplication tables for SQL statements written with the while and if conditions
SQL statement Implementation--x 99 multiplication table in the lower left corner
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 SET @i=@i+ END
SQL statement Implementation--x 99 multiplication table in the lower right corner
DECLARE @i INT,@J INT,@S VARCHAR() SET @i= while @i< BEGIN SET @J= SET @S="' while @J> BEGIN IF @J>@i BEGIN SET @S=@S+' ' --Seven Spaces 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
SQL statement Implementation--9x9 upper right corner
DECLARE @i INT,@J INT,@S VARCHAR( -)SET @i=1 while @i<TenBEGINSET @J=1SET @S="' while @J<TenBEGINIF @J<@iBEGINSET @S=@S+' '--7ENDELSEBEGINSET @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
SQL statement implementation--9x9 Upper left corner
DECLARE @i INT,@J INT,@S VARCHAR( -)SET @i=1 while @i<TenBEGINSET @J=@iSET @S="' while @J<TenBEGINSET @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
sql-Statement Implementation 99 multiplication table