SQL statements implement four types of 9-9 multiplication tables and SQL statements

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.