from 语句中的case 问题
我想实现下面的效果,不知怎么写?
select * from T1
case @Para1 when 1 then inner join T2
end
where .....
谢谢大家执教
------解决方案--------------------不会,帮顶
------解决方案--------------------declare @sql varchar(8000)
select @sql= 'select * from T1 '+case @Para1 when 1 then + ' inner join T2 on ... ' end + ' where ..... '
------解决方案--------------------select * from T1
case @Para1 when 1 then inner join T2
end
where .....
--------------------> >
if @Para1=1
begin
select * from T1 inner join t2
on ....
end
------解决方案--------------------declare @Para1 int
declare @sql varchar(8000)
set @Para1=1
set @sql= case @Para1 when 1 then 'select * from T1 inner join ... ' end
exec(@sql)
------解决方案--------------------declare @sql varchar(4000)
select @sql= 'select * from T1 '+case @Para1 when 1 then + ' inner join T2 on ... ' end + ' where ..... '
exec(@sql)
------解决方案--------------------似乎只有最笨的方法
Declare @Para1 Int
Select @Para1 = 1
If @Para1 = 1
select * from T1
inner join T2
On t1.id = t2.id
where t1.id > 0
Else
select * from T1
where t1.id > 0