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@iInt@JInt@SVARCHAR(100)SET@i=1While@i<10BEGINSET@J=1SET@S=‘‘While@J<=@iBEGINSET@S=@S+CAST (@JAsCHAR (1))+‘*‘+CAST (@iAsCHAR (2))+ ' = +cast ((@i*@J) as char (3)) set @j=@j+1 end print @s set @i=@i+1 end
SQL statement Implementation--x 99 multiplication table in the lower right corner
DECLARE@iInt@JInt@SVARCHAR()SET@i=While@i<BEGINSET@J=SET@S=‘‘While@J>BEGINIF@J>@iBEGINSET@S=@S+‘‘--Seven spacesENDELSEBEGINSET@S=@S+CAST (@iAsCHAR ())+‘*‘+CAST (@JAsCHAR ())+‘= +cast (@i*@j) as char ()) end set @j=@j-end print @s set @i=@i+ end
SQL statement Implementation--9x9 upper right corner
DECLARE@iInt@JInt@SVARCHAR (100)SET@i=1While@i<10BEGINSET@J=1SET@S=‘‘While@J<10BEGINIF@J<@iBEGINSET@S=@S+‘‘--7ENDELSEBEGINSET@S=@S+CAST (@iAsCHAR (1))+‘*‘+CAST (@JAsCHAR (1))+‘=‘+CAST ((@i*as char (3endset @j=@j+ 1endprint @sset @i=@i+1end
SQL statement implementation--9x9 Upper left corner
DECLARE@iInt@JInt@SVARCHAR (100)SET@i=1While@i<10BEGINSET@J=@iSET@S=‘‘While@J<10BEGINSET@S=@S+CAST (@iAsCHAR (1))+‘*‘+CAST (@JAsCHAR (1))+‘=‘+CAST ((@i*@j) as char (3 set @j=@j+ 1endprint @sset @i=@i+1end
sql-Statement Implementation 99 multiplication table