LEFT JOIN多功能 [英] LEFT JOIN multiple function
问题描述
问候,
如果我使用给定查询LEFT JOIN几个函数,其中每个函数的连接条件都不同于另一个。将执行所有这些函数或仅具有正确条件的函数将是执行的函数。我知道我的话可能令人困惑所以我会尝试通过一个例子来解释
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
query LEFT JOIN function1(parameters) on categorycolumn = 1
LEFT JOIN function2(parameters) on categorycolumn = 2
我尝试了什么:
尝试谷歌寻求答案并尝试调试,但SSMS调试器对我不起作用。
What I have tried:
Tried to google for an answer and trying to debug however the SSMS debugger is not working for me.
推荐答案
也许你可以使用 APPLY ,参见这里的例子: sql server - 如何使左外连接成为任何sql表的UD函数? - 堆栈溢出 [ ^ ]
Maybe you can use APPLY, see example here: sql server - How to make left outer join a UD-function with any sql table? - Stack Overflow[^]
将功能放在FROM <中通常是一个坏主意/ code>子句。
。
看看你是否可以将它们移动到SELECT
子句,然后你也可以使用<$过滤它们c $ c> CASE
像这样:
It's performance wise generally a bad idea to put functions in theFROM
clause.
See if you can move them to theSELECT
clause, then you can also filter them using aCASE
.
Like this:
SELECT CASE
WHEN categorycolumn = 1 THEN function1(parameters)
WHEN categorycolumn = 2 THEN function2(parameters)
END AS MyResult
FROM...
如果结果不兼容,很容易分成几个CASE。
If the results arent compatible it's easy enough to split into several CASEs.
这篇关于LEFT JOIN多功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!