如果我在一个存储过程中写多个操作的话,@type作为判断,
CREATE PROC awot_fcl1 
@type
AS
if @type=1
BEGIN    SELECT distinct pPeriod FROM awot_fcl group by pPeriod order by pPeriod descENDif @type=2
BEGIN    SELECT distinct name FROM awot_fcl group by name 
END如果不带判断的调用为:
sql=exec awot_fcl1
如果带判断的又如何调用呢?

解决方案 »

  1.   

    exec awot_fcl1 @type=1
    或者
    exec awot_fcl1 1
      

  2.   

    你是不是少了红字部分?
    CREATE PROC awot_fcl1 
    @type int
    AS
    if @type=1
    BEGIN    SELECT distinct pPeriod FROM awot_fcl group by pPeriod order by pPeriod descENDif @type=2
    BEGIN    SELECT distinct name FROM awot_fcl group by name 
    END
      

  3.   

    没少,哪个type是数词库里没有的字段
      

  4.   


    CREATE PROC awot_fcl1 
    @type int
    AS
    BEGIN
    if @type=1
        SELECT distinct pPeriod FROM awot_fcl group by pPeriod order by pPeriod desc
    if @type=2
        SELECT distinct name FROM awot_fcl group by name 
    END
      

  5.   

    TO:lzw_0736 
    这样的写法还是不行的,
    To:DBA_Huangzj
    是报错,如果是没数据还好一些,
      

  6.   

    代码如下:
    CREATE PROC awot_fcl1
    @type int,
    @yr_dsp datetime,
    @fmonth datetime
    AS
    if @type =1
    BEGIN
    SELECT distinct pPeriod FROM awot_fcl where year(pPeriod)=@yr_dsp group by pPeriod order by pPeriod descENDif @type =2
    BEGIN        select isnull(sum(teu),0) as t1 from awot_fcl WHERE year(pPeriod)=@yr_dsp and month(pPeriod)=@fmonth 
    END调用时:
    exec awot_fcl1 @type=1 “yr_dsp” 
    没有数据
      

  7.   

    exec awot_fcl1 1,后面两个参数还是要加的,比如
    exec awot_fcl1 1,'2013-01-01','2013-02-01'