Wednesday, 7 November 2012

print a triangle of stars using SQL Server


DECLARE @count INT,@num INT,@num1 INT, @space INT, @str varchar(50)
SET @count =10 SET @num = 1
WHILE(@num<=@count)
BEGIN
    SET @num1 = 0 SET @space = @count-@num
    WHILE (@num1<@num)
    BEGIN
        if @str is null
            SET @str = '* '
        ELSE
            SET @str = @str+'* '   SET @num1 = @num1+1
    END
    PRINT (space(@space)+@str)
    SET @num = @num+1   SET @str = null
END

No comments:

Post a Comment