create proc dddd  @xmqc varcher(200)
as
if @xmqc='1'
select * from table1if @xmqc='0'
select * from table2if @xmqc<>'1'or @xmqc<>'0'
select * from table3 where table3_xmqc like '%'+@xmqc+ '%'

解决方案 »

  1.   

    create proc dddd @xmqc varcher(200)
    as
    if @xmqc='1'
    select * from table1
    else
    begin
    if @xmqc='0'
    select * from table2
    else
    begin
    select * from table3 where table3_xmqc like '%'+@xmqc+ '%'
    end
    end
      

  2.   

    create proc dddd @xmqc varcher(200)
    as
    if @xmqc='1'
    select * from table1
    else
    begin
    if @xmqc='0'
    select * from table2
    else  ----这个地方提示错误
    begin
    select * from table3 where table3_xmqc like '%'+@xmqc+ '%'
    end
    end
    --------------------------------
      

  3.   

    完整的sql如下:请指教!/*物业收入统计表*/
    create    PROC  wysrtjb (@xmqc VARCHAR(200))
    as
    if  @xmqc='1'
    select  c.zwpzk_pzbh,c.zwpzk_pzrq,b.lshsxm_xmnm ,b.lshsxm_xmqc ,b.lshsxm_sj01,b.lshsxm_sj02,b.lshsxm_sj03,b.lshsxm_sj04,
    b.lshsxm_xm01,a.zwfzys_sm01,a.zwfzys_sm02,a.zwfzys_je from zwfzys2007 a 
    inner join lshsxm2007 b on substring(a.zwfzys_xmbh,22,30)=b.lshsxm_xmbh 
    inner join zwpzk2007 c on a.zwfzys_pznm=c.zwpzk_pznm
    where a.zwfzys_kmbh like '5101%' and a.zwfzys_dwbh='0105' and a.zwfzys_jzfx='2' and 
    substring(a.zwfzys_xmbh,22,30)=b.lshsxm_xmbh and b.lshsxm_lbbh='04' and c.zwpzk_dwbh='0105'
    order by b.lshsxm_xmnm,a.zwfzys_sm02,c.zwpzk_pzrq
    else
    begin
    if  @xmqc='0' 
    select  c.zwpzk_pzbh,c.zwpzk_pzrq,b.lshsxm_xmnm ,b.lshsxm_xmqc ,b.lshsxm_sj01,b.lshsxm_sj02,b.lshsxm_sj03,b.lshsxm_sj04,
    b.lshsxm_xm01,a.zwfzys_sm01,a.zwfzys_sm02,a.zwfzys_je into #yzfh2 from zwfzys2007 a 
    inner join lshsxm2007 b on substring(a.zwfzys_xmbh,22,30)=b.lshsxm_xmbh 
    inner join zwpzk2007 c on a.zwfzys_pznm=c.zwpzk_pznm
    where a.zwfzys_kmbh like '5101%' and a.zwfzys_dwbh='0105' and a.zwfzys_jzfx='2' and 
    substring(a.zwfzys_xmbh,22,30)=b.lshsxm_xmbh and b.lshsxm_lbbh='04' and c.zwpzk_dwbh='0105'
    order by b.lshsxm_xmnm,a.zwfzys_sm02,c.zwpzk_pzbh,c.zwpzk_pzrq
    insert into #yzfh2(zwpzk_pzbh,zwpzk_pzrq,lshsxm_xmnm,lshsxm_xmqc,lshsxm_sj01,lshsxm_sj02,lshsxm_sj03,lshsxm_sj04,lshsxm_xm01)
    select 'NULL','NULL',lshsxm_xmnm,lshsxm_xmqc,lshsxm_sj01,lshsxm_sj02,lshsxm_sj03,lshsxm_sj04,lshsxm_xm01 from lshsxm2007 where lshsxm_lbbh='04' and lshsxm_xmnm not in (select lshsxm_xmnm from #yzfh2)order by lshsxm_xmnm
    select * from #yzfh2  order by LSHSXM_xmnm,ZWFZYS_sm02,ZWPZK_pzbh,ZWPZK_pzrq
    else
    begin
    select  c.zwpzk_pzbh,c.zwpzk_pzrq,b.lshsxm_xmnm ,b.lshsxm_xmqc ,b.lshsxm_sj01,b.lshsxm_sj02,b.lshsxm_sj03,b.lshsxm_sj04,
    b.lshsxm_xm01,a.zwfzys_sm01,a.zwfzys_sm02,a.zwfzys_je into #yzfh3 from zwfzys2007 a 
    inner join lshsxm2007 b on substring(a.zwfzys_xmbh,22,30)=b.lshsxm_xmbh 
    inner join zwpzk2007 c on a.zwfzys_pznm=c.zwpzk_pznm
    where a.zwfzys_kmbh like '5101%' and a.zwfzys_dwbh='0105' and a.zwfzys_jzfx='2' and 
    substring(a.zwfzys_xmbh,22,30)=b.lshsxm_xmbh and b.lshsxm_lbbh='04' and c.zwpzk_dwbh='0105'
    order by b.lshsxm_xmnm,a.zwfzys_sm02,c.zwpzk_pzbh,c.zwpzk_pzrq
    insert into #yzfh3(zwpzk_pzbh,zwpzk_pzrq,lshsxm_xmnm,lshsxm_xmqc,lshsxm_sj01,lshsxm_sj02,lshsxm_sj03,lshsxm_sj04,lshsxm_xm01)
    select 'NULL','NULL',lshsxm_xmnm,lshsxm_xmqc,lshsxm_sj01,lshsxm_sj02,lshsxm_sj03,lshsxm_sj04,lshsxm_xm01 from lshsxm2007 where lshsxm_lbbh='04' and lshsxm_xmnm not in (select lshsxm_xmnm from #yzfh)order by lshsxm_xmnm
    select * from #yzfh3 where lshsxm_xmqc like '%'+@xmqc+'%'
    end
    end
    -----------------------------------------------服务器: 消息 156,级别 15,状态 1,过程 wysrtjb,行 25
    Incorrect syntax near the keyword 'else'.
      

  4.   

    create proc dddd @xmqc varchar(200)
    as
    if @xmqc='1'
    select * from table1
    else
    begin
    if @xmqc='0'
    select * from table2
    else ----这个地方提示错误
    begin
    select * from table3 where table3_xmqc like '%'+@xmqc+ '%'
    end
    end没错,执行同过了