参数@abc
如果@abc的值为‘1’就执行一条SQL语句
如果@abc的值为‘2’就执行一条SQL语句
如果@abc的值为‘3’就执行一条SQL语句
否则
执行一条SQL语句

解决方案 »

  1.   

    declare @abc int
    set @abc = 1
    if @abc=1else if @abc=2else if @abc=3else
      

  2.   

    declear @sql varchar(1000)
    if @abc='1'
     begin
      set @sql='语句1'
     end
    else
    if @abc='2'
     begin
      set @sql='语句2'
     end
    else
      if@abc='3'
      begin 
        set @sql='语句3'
      end
    exec @sql
      

  3.   

    --這樣declare @abc int
    set @abc = 1if @abc=1
    begin
    select ...
    end
    else if @abc=2
    begin
    select ...
    end
    else if @abc=3
    begin
    select ...
    end
    else
    begin
    select ...
    end
      

  4.   

    嗯,直接用if ........else就行了呀
      

  5.   

    case when ... then ... when ... then ... else ... end
      

  6.   

    --例子
    use pubs declare @abc int
    declare @sql varchar(1000)set @abc = 2   --这个地方是你传过来的值--这个地方是选择
    select @sql = 
    CASE
        WHEN @abc = 1 THEN 'select au_id from authors'
        WHEN @abc = 2 THEN 'select au_lname from authors'
        WHEN @abc = 3 THEN 'select au_fname from authors'
        ELSE 'select * from authors'
    END
    exec(@sql)   --动态执行sql语句
      

  7.   

    那就用case when ... then ...吧
      

  8.   

    case when ... then ...else end