请教高手如何通过print打印一个正方形图案

wdz0909 2006-02-16 09:58:17
请问如何通过sql函数print打印如下的图案:

**********
* *
**********

希望用while循环来实现,谢谢~~
...全文
282 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2006-02-16
  • 打赏
  • 举报
回复

declare @I int
declare @J int
declare @rowmax int
declare @colmax int
set @rowmax = 5
set @colmax = 5
select @i = @rowmax,@j = @colmax
declare @s varchar(100)
while @i>0
begin
set @s = ''
while @j>0
begin
set @s = @s +
case when (@j = 1 or @j = @colmax) or (@i = 1 or @i = @rowmax) then '*' else ' ' end
set @j = @j -1
end
set @i = @i -1
set @j = 5
print @s
set @s = ''
end

/*

*****
* *
* *
* *
*****
*/
ReViSion 2006-02-16
  • 打赏
  • 举报
回复
不知道你想用while来控制什么东东
ReViSion 2006-02-16
  • 打赏
  • 举报
回复
为什么一定要用while
print'**********
* *
**********'

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧