我想让他执行完存储过程后显示成这样
月份     人数
  1        2
于是我创建:
create proc shengri 
@a int,@b int output 
as 
select @a=month(birthdate) 月份,@b=count(*) 人数 
from employees 
where @a=month(birthdate) 
group by month(birthdate) 
显示月份附近有错误。不加月份和人数编译成功
然后运行:
declare @b int
exec shengri '1',@b output
print @b
只是显示一个  2
请教想让他显示成我想要那种样子,该如何改一改呢?

解决方案 »

  1.   

    select @a=month(birthdate) 月份,@b=count(*) 人数 
    from employees 
    where @a=month(birthdate)   --不能这样
    group by month(birthdate) 
    改用动态吧!
      

  2.   

    你要显示上面的HEAD?  直接打出来不就好了嘛
      

  3.   

    create proc shengri 
    @a int --月份
    as 
    select  @a as 月份,count(*) as 人数
    from employees 
    where @a=month(birthdate) 
    GO
    如果只是要那个结果,这样就可以了,调用:
    exec shengri 1
      

  4.   

    create proc shengri 
    @a int,@b int output
    as 
    select @a=month(birthdate),@b=count(*) 
    from employees 
    where @a=month(birthdate) 
    group by month(birthdate)  
    declare @b int 
    exec shengri '1', @b outputselect @b as 人数--try 
      

  5.   


    create proc shengri 
    @a int 
    as 
    select month(birthdate) 月份,count(*) 人数 
    from employees 
    where @a=month(birthdate) 
    group by month(birthdate) 
    go
    exec shengri 1
      

  6.   

    CREATE TABLE  #tb1
    ( birthdate datetime ,id int identity)
    INSERT #tb1
    SELECT  '2009-01-06' UNION ALL 
    SELECT  '2009-02-06' UNION ALL 
    SELECT  '2009-02-06' UNION ALL 
    SELECT  '2009-03-06' 
    GO
    create proc shengri 
    @a int
    as 
    select month(birthdate) 月份,count(*) 人数
    from #tb1 
    where @a=month(birthdate) 
    group by month(birthdate) 
    go
     exec shengri 1月份          人数
    ----------- -----------
    1           1(1 行受影响)
    drop proc shengri
    drop table #tb1
      

  7.   

    create proc shengri 
    @a int,@b int output
    as 
    select @a=month(birthdate),@b=count(*) 
    from employees 
    where month(birthdate) 
    group by month(birthdate) set @b=cast(@b as varchar)+cast(@a as varchar)
     
    declare @b int 
    exec shengri '1', @b outputselect @b as 人数