下面用while 和 if 条件写的SQL语句的四种九九乘法表
sql语句实现--x 左下角九九乘法表
DECLARE @I INT ,@J INT,@S VARCHAR(100)
SET @I=1
WHILE @I<10
BEGIN
SET @J=1
SET @S=''
WHILE @J<=@I
BEGIN
SET @S=@S+CAST(@J AS CHAR(1))+'*'+CAST(@I AS CHAR(2))+'='+CAST((@I*@J)AS CHAR(3))
SET @J=@J+1
END
PRINT @S
SET @I=@I+1
END
sql语句实现--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+' ' --七个空格
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语句实现--9X9右上角
DECLARE @I INT ,@J INT,@S VARCHAR(100)
SET @I=1
WHILE @I<10
BEGIN
SET @J=1
SET @S=''
WHILE @J<10
BEGIN
IF @J<@I
BEGIN
SET @S=@S+' '--
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
sql语句实现--9X9左上角
DECLARE @I INT ,@J INT,@S VARCHAR(100)
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