declare @exp1 int,@exp2 int,@exp3 int,@totle int
select @exp1 = 1,@exp2 = 1,@exp3 = 1
select @i = 5
while @i <> 0
begin
    @exp1 = @exp1 * @i
    @i = @i - 1
endselect @i = 6
while @i <> 0
begin
    @exp1 = @exp1 * @i
    @i = @i - 1
endselect @i = 8
while @i <> 0
begin
    @exp1 = @exp1 * @i
    @i = @i - 1
endselect @totle = @exp1 + @exp2 + @exp3

解决方案 »

  1.   

    drop proc p10
    create proc p10 (@in int, @out int output) as
    declare @o1 int
    declare @i1 int
    if @in <= 1
       set @out = 1
    else
    begin
       set @i1 = @in - 1
       exec sp_executesql N'exec p10 @i1, @o1 output',
                          N'@i1 int, @o1 int output',
                          @i1, @o1 output
                  
       set @out = @in * @o1
    end 
    returndeclare @o1 int
    declare @o2 int
    declare @o3 int
    exec p10 5, @o1 output
    exec p10 6, @o2 output
    exec p10 8, @o3 output
    select @o1 + @o2 + @o341160
      

  2.   

    感谢以上二位,还有一题相求
    某商场销售数据库有如下关系模式
    SP(商品号,商品名,型号,单位,单价)
    YG(员工号,姓名,年龄,部门)
    XS(商品号,数量,金额,日期,员工号)
    用SQL 描写 1,该商场销售过的所有商品的编号,名称,型号,单价。
    2 ,销售额最好员工的姓名和所在部门
    3,按员工的销售额从多到少输出员工的姓名,部门,销售金额。
      

  3.   

    1.select distinct xs.商品号,商品名,型号,单价 from xs,sp where xs.商品号=sp.商品号2.select 员工号,姓名,部门,max(销售额) as 销售额 from (select xs.员工号,姓名,部门,sum(金额) as 销售额  from xs,yg where xs.员工号=yg.员工号 group by xs.员工号,姓名,部门) as xse3.select 员工号,姓名,部门,销售额 from (select xs.员工号,姓名,部门,sum(金额) as 销售额  from xs,yg where xs.员工号=yg.员工号 group by xs.员工号,姓名,部门) as xse oder by 销售额 desc ---销售排行榜