I have a view with code as follows
create view v1
as
section1 --I get column1 data here
union all
section2 --I get column2 data here
union all
section3 --I get column3 data here
Now, this view is used in multiple places and will be joined on column1 or 2 or 3 depending upon the place where we use this like below.
select * from tabl1 t1 join v1 on t1.column1 = v1.column1
select * from tabl1 t2 join v1 on t2.column2 = v1.column2
etc
But if it is joining on column1, computation for column2,3 i.e, section 2,3 is not needed. As per current business rules, we cant split the view into multiple views. Now, what I need is that if view gets joined on column1, section2,3 should not be computed and similar is case with column2,section1,3 and column3,section1,2
Could someone please help me how to achieve this
Thanks, Sree
union allby itself. Have you looked at query plans?