大家使劲批批这个存储过程,到底有什么问题,没改好
CREATE   proc   zjreport1 
 ( 
 @companyname   varchar(100)=null, 
 @startdate   datetime=null, 
 @enddate   datetime=null 
 ) 
 as 
 begin 
 /*   *****************这一段在查询分析器中测试正常**********************   */ 
 select   公司名称zy   as   公司名称,sum(批复金额)   as   申请用款总额   from   ( 
 select   *   from   (select   公司名称,批复金额,请求时间   from 
 ( 
       select   *   from   v_shenp 
       union   all 
       select   *   from   shenp_v_b    
 )   t   where   审批意见= '同意 ')   a   ,duizhaobiao   b   where   b.公司名称sp=a.公司名称)   ccc    
 /*   *******************上面的************************   */ 
 and   公司名称=(case   when   @companyname   is   null   then   公司名称   else   @companyname   end) 
 and   请求时间> (case   when   @startdate   is   null   then   请求时间-1   else   @startdate   end) 
 and   请求时间 <(case   when   @enddate   is   null   then   请求时间+1   else   @enddate   end) 
 group   by   公司名称zy 
 Go 
------解决方案--------------------begin 
 /* *****************这一段在查询分析器中测试正常********************** */ 
 select 公司名称zy as 公司名称,sum(批复金额) as 申请用款总额 from ( 
 select * from (select 公司名称,批复金额,请求时间 from 
 ( 
   select * from v_shenp 
   union all 
   select * from shenp_v_b  
 ) t where 审批意见= '同意 ') a ,duizhaobiao b where b.公司名称sp=a.公司名称) ccc  
 /* *******************上面的************************ */ 
 --这儿好象多了个and,切少了where 
 where 公司名称=(case when @companyname is null then 公司名称 else @companyname end) 
 and 请求时间> (case when @startdate is null then 请求时间-1 else @startdate end) 
 and 请求时间 <(case when @enddate is null then 请求时间+1 else @enddate end) 
 group by 公司名称zy 
 Go 
------解决方案--------------------CREATE proc zjreport1 
 ( 
 @companyname varchar(100)=null, 
 @startdate datetime=null, 
 @enddate datetime=null 
 ) 
 as   
 /* *****************这一段在查询分析器中测试正常********************** */ 
 select 公司名称zy as 公司名称,sum(批复金额) as 申请用款总额 from ( 
 select * from (select 公司名称,批复金额,请求时间 from 
 ( 
   select * from v_shenp 
   union all 
   select * from shenp_v_b  
 ) t where 审批意见= '同意 ') a ,duizhaobiao b where b.公司名称sp=a.公司名称) ccc  
 where  公司名称=(case when @companyname is null then 公司名称 else @companyname end) 
 and 请求时间> (case when @startdate is null then 请求时间-1 else @startdate end) 
 and 请求时间 <(case when @enddate is null then 请求时间+1 else @enddate end) 
 group by 公司名称zy 
 Go
------解决方案--------------------两个问题,begin多了,没有与begin相对应的end在你的代码中, 
 另外ccc后面的and改成where,没有where语句