SQL statement implementation four kinds of 99 multiplication table _mssql

Source: Internet
Author: User

The following four kinds of 99 multiplication tables of SQL statements written with the while and if conditions

SQL statement implementation--x lower left corner 99 multiplication table

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< C14/>set @i=@i+ End
 

Results:

SQL statement implementation--x right lower corner 99 multiplication table

DECLARE @i INT, @j int,@s VARCHAR ()
 set @i= while
 @i<
 BEGIN
 set @j=
 set @s= ' while
 @j& gt;
 Begin
 IF @j>@i
 begin
 Set @s=@s+ '    --seven space 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

Results:

SQL statement Implementation--9x9 upper right corner

DECLARE @i INT, @j int,@s VARCHAR (m)
set @i=1 while
@i<10
BEGIN 
set @j=1
set @s= "while
@j <10
begin 
IF @j<@i
begin
Set @s=@s+ '    --7 end
ELSE 
begin 
Set @s= @s+cast (@i as char (1)) + ' * ' +cast (@j as char (1)) + ' = ' +cast ((@i*@j) as char (3))
end
SET @j=@j+1 end
PRINT @S
SET @i=@i+1
End

Results:

SQL statement implementation--9x9 Upper left corner

DECLARE @i INT, @j int,@s VARCHAR (m)
set @i=1 while
@i<10
BEGIN
set @j=@i
set @s= '
While @j<10
BEGIN 
SET @s=@s+cast (@i as char (1)) + ' * ' +cast (@j as char (1)) + ' = ' +cast ((@i*@j) as char (3))
SET @j=@j+1
End
PRINT @S
SET @i=@i+1
End

Results:


The above content is through four ways to write 99 multiplication table, I hope you like.

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.