我的一个过程
create procedure crmdbo.gzzq_brokerjjrfyjshzb_cx
      @client_branch_no                   BranchNo            ,           
      @branch_no                          varchar(200)        ,       
      @begin_date                         IntDate             ,         
      @end_date                           IntDate             ,          
      @broker_account                     BrokerAccount       ,      
as---这一段作怪,为A段
declare   @sql   varchar(8000)
 select @sql = 'create table #tempshow(month_id   int not null, branch_no varchar(8) not null, branch_no_shou varchar(8) not null,' +
   'fare1  numeric(19,2)  not null, branch_no_fu   varchar(8)  not null, fare2  numeric(19,2) not null)'
exec(@sql)                                                               
go          
--这一段做怪 if object_id( 'tempdb..#temp') is not null 
   drop table #temp
select distinct month_id, branch_no  into  #temp  from  crmcurrent.crmdbo.gzzq_brokerjjrfyjsmxb
where month_id between @begin_date/100 and @end_date/100
and (@branch_no = '' or rtrim(branch_no)= rtrim(@branch_no))
order by month_id, branch_no
一直 提示 错误:
消息 137,级别 15,状态 2,第 7 行
必须声明标量变量 "@begin_date"。
消息 137,级别 15,状态 2,第 70 行
必须声明标量变量 "@branch_no"。
消息 137,级别 15,状态 2,第 73 行
必须声明标量变量 "@branch_no"。上面提示的全部是过程自带的参数,就是因为A段存在(这段语法没问题的),提示这个错误,没有A断就正常。我的疑问:难道过程里面不能create table?为什么加上那段,过程变量就失效了呢???              

解决方案 »

  1.   

    @client_branch_no BranchNo ,   
      @branch_no varchar(200) , 
      @begin_date IntDate ,   
      @end_date IntDate ,   
      @broker_account BrokerAccount , 这是啥类型呀 
      

  2.   

    create procedure crmdbo.gzzq_brokerjjrfyjshzb_cx
      @client_branch_no BranchNo ,   
      @branch_no varchar(200) , 
      @begin_date IntDate ,   
      @end_date IntDate ,   
      @broker_account BrokerAccount ,   
    as
      

  3.   

      @begin_date IntDate ,  
      @end_date IntDate ,  
    ------------IntDate 是自定义的数据类型?
      

  4.   


    exec(@sql)  
    go  
    -------------
    就这个go的问题啦,到此你的存储过程结束了,下面的变量当然失效。
      

  5.   

    select @sql = 'create table #tempshow(month_id int not null, branch_no varchar(8) not null, branch_no_shou varchar(8) not null,' +
      'fare1 numeric(19,2) not null, branch_no_fu varchar(8) not null, fare2 numeric(19,2) not null)'
    exec(@sql)  你这里面根本没变量,干嘛整个动态SQL语句