create proc dbo.Proc_Get_Data
    @iYear as int, 
    @iMonth as int,
    @ItemCode varchar(50),   
 
    @type varchar(50),    @GroupType varchar(50)=''
as if @GroupType=''
   begin
     
           select * from table where iYear=@iYear and @iMonth=@iMonth and ItemCode= @ItemCode and type=@type  
   endGO--==
select * from table where  iYear='2007' and iMonth='8' and itemcode='All'and type='库存物料‘结果:可以取得记录。
exec Proc_Get_KPI_Data  N'2007', N'8',N'All', N'库存物料,''
结果:不可以取得记录。
请问2种方法主要有什么区别啊。急。。

解决方案 »

  1.   

    好写的东东用SQL.
    不好写的,如循环,判断,不固定的值...用存储过程
      

  2.   

     @iYear   as   int,   
     @iMonth   as   int, 
     iYear= '2007 '   and   iMonth= '8 ' 
    exec   Proc_Get_KPI_Data     N '2007 ',   N '8 ',N 'All ',   N '库存物料, ' ' 
    明显类型不一样啊,把存储过程的变量类型改了
      

  3.   

            @iYear   as   int,   
            @iMonth   as   int, 
    应该是这两个变量的类型有问题。改成你创建表时这两个字段的类型。
      

  4.   

    --少了一个'
    exec  Proc_Get_KPI_Data  N'2007',  N'8',N'All', N'库存物料', '' 
      

  5.   

    存储过程中语句是编译好的,执行时会比直接用sql 快一些