How to replace union in stored procedure in sql server -


i have stored procedure having below queries. there way replace union 1 query or other way optimize it.

select col1,col2 logs lg inner join employeetype_1 et1 on et1.empid=lg.userid lg.usertype=1  union   select col1,col2 logs lg inner join employeetype_2 et2 on et2.empid=lg.userid lg.usertype=2  union   select col1,col2 logs lg inner join employeetype_3 et3 on et13.empid=lg.userid lg.usertype not in (1,2) 

presumably, col1 , col2 come logs. here 1 way:

select col1,col2 logs lg (lg.usertype = 1 , exists (select employeetype_1 et1 et1.empid = lg.userid) ) ,       (lg.usertype = 2 , exists (select employeetype_2 et1 et1.empid = lg.userid) ) ,       (lg.usertype not in (1, 2) , exists (select employeetype_3 et1 et1.empid = lg.userid) ) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -