Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a triangle in SQL Server?

Tags:

sql-server

How to draw triangles in SQL Server as shown below?

enter image description here

I want to implement it by using WHILE loops, but I am unable to print 20 '*' in a single line in SQL Server.

How can I achieve this?


1 Answers

Use REPLICATE inside a WHILE. I think, you can achieve your desired output if you do it correctly?

DECLARE @i INT = 20

WHILE(@i>0)
BEGIN
   PRINT REPLICATE('* ', @i);
   SET @i = @i - 1;
END

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!