SQL statements implement four types of 9-9 multiplication tables and SQL statements
The following four types of 9-9 multiplication tables of SQL statements written with the while and if conditions
SQL statement implementation -- 9-9 multiplication table in the lower left corner of x
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
Result:
SQL statement implementation -- 9-9 multiplication table in the lower right corner of X
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
Result:
SQL statement implementation -- 9X9 upper right corner
DECLARE @I INT ,@J INT,@S VARCHAR(100)SET @I=1WHILE @I<10BEGIN SET @J=1SET @S=''WHILE @J<10BEGIN 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
Result:
SQL statement implementation -- 9X9 upper left corner
DECLARE @I INT ,@J INT,@S VARCHAR(100)SET @I=1WHILE @I<10BEGINSET @J=@ISET @S=''WHILE @J<10BEGIN 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
Result:
The preceding content is a nine-nine multiplication table written in four ways.