如何在 SQL Server 中绘制三角形? [英] How to draw a triangle in SQL Server?

查看:40
本文介绍了如何在 SQL Server 中绘制三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SQL Server 中绘制三角形如下图所示?

How to draw triangles in SQL Server as shown below?

我想通过使用 WHILE 循环来实现它,但我无法在 SQL Server 的一行中打印 20 个*".

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?

推荐答案

在 WHILE 中使用 REPLICATE.我想,如果你做对了,你能达到你想要的输出吗?

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

这篇关于如何在 SQL Server 中绘制三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆