tengo este query y la verdad no se como modificarle otra condicion ya que necesito que solo me considere un campo de la tabla "a" si este esta como true`
set @auxSdu=' '
set @auxTeam=' '
set @auxGroup=' '
set @auxLm=' '
if @sdu <> 'All'
set @auxSdu='e.[id_sdu]='''+@sdu+''' AND'
if @team <> 'All'
set @auxTeam='g.[id_team]in ('''+@team+''') AND'
if @team = 'All'
begin
insert #team select * from [RIA].[dbo].[cat_team] where [id_domain]in(select [id_domain] from [RIA].[dbo].[cat_domain] where [description]=@domain) and [id_region]in(select [id_region] from [RIA].[dbo].[cat_region] where [description]=@region)
insert #team select * from [RIA].[dbo].[cat_team] where [id_team] in( select [id_team] from ria.dbo.[group] where [id_group]in(select [id_group] from ria.dbo.[group] where [id_team]in(SELECT [id_team] FROM [RIA].[dbo].[cat_team] where [id_domain]in(select [id_domain] from [RIA].[dbo].[cat_domain] where [description]=@domain) and [id_region]in(select [id_region] from [RIA].[dbo].[cat_region] where [description]=@region))))
set @auxTeam='g.[id_team]in (select [id_team] from #team group by [id_team]) AND'
end
if @group <> 'All'
set @auxGroup='g.[id_team]in ( select distinct[id_team] from [RIA].[dbo].[group] where [id_group] in ('''+@group+''')) AND'
if @lm <> 'All'
set @auxLm='b.[id_lm]in ('''+@lm+''') AND'
set @sql='select a.[id_signum],(b.[last_name]+'', ''+b.[first_name]) as [name],a.[jobStage],b.[id_cats],b.[id_ah],b.[ah],lower(j.[signum]) as [lm],(j.[last_name]+'', ''+j.[first_name]) as [lmName], lower(k.[signum]) as [om],(k.[last_name]+'', ''+k.[first_name]) as [omName],c.[description] as [domian], d.[description] as [subdomian], e.[description] as [sdu], f.[description] as [serviceArea],[gtt],[start_date],[final_date], g.[description] as [team], h.[description] as [region], i.[description] as [customer],[tg2],[shift],l.[description]as[country],a.[typeProject]
from [RIA].[dbo].[resource_tracking] a,
[RIA].[dbo].[resources] b,
[RIA].[dbo].[cat_domain] c,
[RIA].[dbo].[cat_subdomain] d,
[RIA].[dbo].[cat_sdu] e,
[RIA].[dbo].[cat_serviceArea] f,
[RIA].[dbo].[cat_team] g,
[RIA].[dbo].[cat_region] h,
[RIA].[dbo].[cat_customer] i,
[RIA].[dbo].[manager] j,
[RIA].[dbo].[manager] k,
[RIA].[dbo].[cat_country] l
where
a.[id_signum]=b.[signum] AND
g.[id_domain]=c.[id_domain] AND
a.[id_subdomain]=d.[id_subdomain] AND
a.[id_sdu]=e.[id_sdu] AND
a.[id_service_area]=f.[id_pa] AND
a.[id_team]=g.[id_team] AND
g.[id_region]=h.[id_region] AND
a.[id_customer]=i.[id_customer] AND
b.[id_lm]=j.[id_manager] AND
b.[id_om]=k.[id_manager] AND
a.[id_country]=l.[id_country] AND
'+@auxSdu+@auxTeam+@auxGroup+@auxLm+'
((a.[start_date]<='''+convert(varchar(20),@startDate)+''' and a.[final_date]>='''+convert(varchar(20),@endDate)+''') or
(a.[start_date]> '''+convert(varchar(20),@startDate)+''' and a.[start_date]<='''+convert(varchar(20),@endDate)+''' and a.[final_date]>='''+convert(varchar(20),@endDate)+''') or
(a.[start_date]<='''+convert(varchar(20),@startDate)+''' and a.[final_date]>='''+convert(varchar(20),@startDate)+''' and a.[final_date]< '''+convert(varchar(20),@endDate)+''') or
(a.[start_date]> '''+convert(varchar(20),@startDate)+''' and a.[final_date]< '''+convert(varchar(20),@endDate)+''' and a.[start_date]<= a.[final_date]))'
insert #trackingAll exec(@sql)
no se si me pueden dar una idea de como lo puedo lograr, desde ya gracias!