select *
from 表1 t1
join 表2
  on 字段1 like 'L01%' and 其他关联条件union allselect *
from 表1 t1
join 表3
  on 字段1 like 'JHA%' and 其他关联条件  

解决方案 »

  1.   

    declare @sql varchar(max)
    set @sql=''
    select @sql='select * from 表1 join '+case when (select 字段1 from 表1 where id=1 )='JHA' then 表3 else 表2 end )
    print (@sql)你试试,我假设你的表1有一个ID来判断第一行
      

  2.   

    这个需求当然是if else, 花稍的东西只会给自己以后带来麻烦。
      

  3.   

    各位别走,帮忙写个if else 啊
      

  4.   

    if (select 字段1 from 表1 where id=1)='L01'
    begin
        select * from 表1 inner join 表2
    end
    else 
    begin
        select * from 表1 inner join 表3
    end