--是这个意思吗?create view 视图名
as
select a.*,b.字段
from 表a a join 表b b on a.id=b.id
where a.标志=1
union all
select a.*,c.字段
from 表a a join 表c c on a.id=c.id
where a.标志=2

解决方案 »

  1.   

    存在一个主表wszfk 其中
     如果字段szdm='01' 就要与dsdm01连接
     如果字段szdm='02' 就要与表dsdm02连接
     如果字段szdm='04' 就要与表dsdm03连接
     如果字段szdm='30' 就要与表dsdm30连接
     如果字段szdm='32' 就要与表dsdm32连接
    该怎么写????
      

  2.   

    --用动态语句(猜的):
    declare @sql varchar(10)
    set @sql='select * from tablename a join '
    select @sql=@sql+ (case col1 when 'value1' then 'tablename2 b on a.id=b.id' else
                        'tablename3 b on a.id=b.id' end) from anothertable where id='value'  
    exec(@sql)
      

  3.   

    --像我上面的示例那样的结果? 还是其他结果?--是这个意思吗? 最好能举数据说明一下:select * 
    from wszfk m
    join dsdm01 c1 on m.id=c1.id and m.szdm='01'
    join dsdm02 c2 on m.id=c2.id and m.szdm='02'
    join dsdm03 c3 on m.id=c3.id and m.szdm='03'
    join dsdm30 c4 on m.id=c4.id and m.szdm='30'
    join dsdm32 c5 on m.id=c5.id and m.szdm='32'