用SQL语句打印等腰三角形
要求用指定的字符(*、&等)打印三角形,要求字符的个数变化是:1、3、5、7、9.............. sql
[解决办法]
DECLARE @CountINT=1;
DECLARE @ColsINT=10;
--IF(@Count%2=1)
WHILE @Count<=@Cols
BEGIN
IF(@Count%2=1)
PRINT SPACE((@Cols-@Count)/2)+REPLACE(SPACE(@Count),' ','*')+SPACE((@Cols-@Count)/2)
SET @Count=@Count+1
END
/*
*
***
*****
*******
*********
*/
DECLARE @CountINT=1;
DECLARE @ColsINT=10;
--IF(@Count%2=1)
WHILE @Count<=@Cols
BEGIN
IF(@Count%2=1)
PRINT SPACE((@Cols-@Count)/2)+REPLACE(SPACE(@Count),' ','*')+SPACE((@Cols-@Count)/2)
SET @Count=@Count+1
END
SET @Count=@Count-2
WHILE @Count>=0
BEGIN
IF(@Count%2=1)
PRINT SPACE((@Cols-@Count)/2)+REPLACE(SPACE(@Count),' ','*')+SPACE((@Cols-@Count)/2)
SET @Count=@Count-1
END
/*
*
***
*****
*******
*********
*********
*******
*****
***
*
*/