Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings,

If I LEFT JOIN several functions with a given query with each one of them having a join condition different from the other one. Will all those functions execute or the one with the correct condition only will be the one that is executed. I know that my words may be confusing so I will try to explain by an example

SQL
query LEFT JOIN function1(parameters) on categorycolumn = 1
      LEFT JOIN function2(parameters) on categorycolumn = 2


What I have tried:

Tried to google for an answer and trying to debug however the SSMS debugger is not working for me.
Posted
Updated 22-Aug-17 23:01pm

 
Share this answer
 
Comments
Amr Mohammad Rashad 21-Aug-17 16:12pm    
Both APPLY operator or the JOIN operator can be used and will have the same result but I was asking from the performance point of view that is from one side. From another side I was asking if there is a way preventing the execution of the query within the function instead of using IF statements within the function body to do such prevention.
It's performance wise generally a bad idea to put functions in the FROM clause.
See if you can move them to the SELECT clause, then you can also filter them using a CASE.
Like this:
SQL
SELECT  CASE 
            WHEN categorycolumn = 1 THEN function1(parameters) 
            WHEN categorycolumn = 2 THEN function2(parameters)
        END AS MyResult
FROM...

If the results arent compatible it's easy enough to split into several CASEs.
 
Share this answer
 
Comments
Amr Mohammad Rashad 12-Sep-17 5:58am    
I will check if that can be done in my case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900