--打印如下图形(行数由变量@Line指定):
-- *
-- *@*
-- *@*@*
-- *@*@*@*
--*@*@*@*@*--四则运算,根据提供的两个数@a,@b及运算符@p,执行+、-、*、/运算。
--若运算符不是+、-、*、/,则提示运算符不正确。
--(要求采用case……end结构实现)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 对TSQL不怎么了解,求高手帮忙解决下
-- *
-- *@*
-- *@*@*
-- *@*@*@*
--*@*@*@*@*--四则运算,根据提供的两个数@a,@b及运算符@p,执行+、-、*、/运算。
--若运算符不是+、-、*、/,则提示运算符不正确。
--(要求采用case……end结构实现)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 对TSQL不怎么了解,求高手帮忙解决下
declare @i int set @i=5
declare @t table (col varchar(8000))
while (@i>0)
begin
insert into @t select '*'+replicate('@*',@i-1)
set @i=@i-1
end
select * from @t order by 1
/*
col
------------
*
*@*
*@*@*
*@*@*@*
*@*@*@*@*
*/
declare @a int set @a=12
declare @b int set @b=3
declare @p varchar(20) set @p='+'select 结果=
case @p when '+' then ltrim(@a+@b) when '-' then ltrim(@a-@b) when '*' then ltrim(@a*@b)
when '/' then ltrim(@a/@b) else '运算符不正确' end/*
结果
------------
15
*/
declare @line int,@i int
set @line=5
set @i=0
while @i<@line
begin
declare @str varchar(4000)
set @str=space((@line-@i)/2)+'*'+REPLICATE('@*',@i)
set @i=@i+1
print @str
end
/*
*
*@*
*@*@*
*@*@*@*
*@*@*@*@*
*/