sql-Statement Implementation 99 multiplication table

Source: Internet
Author: User

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

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.