[英]when condition is true then inner join comes in sql server
I want to do inner join when some condition is true 我想在某些条件为真时进行内部联接
case
when (select dbo.fnGetProduct_config('CATEGORY_NAME','',''))='XYZ'
then inner join product_master t12 on t12.id=t1.product_id
END
You can't use a conditional to decide whether or not to join (except with dynamic sql), but you can add the predicate to the join.... 你不能使用条件来决定是否要参加(除了动态SQL),但你可以在加入添加谓词....
...
from table1
inner join product_master t12 on t12.id=t1.product_id and dbo.fnGetProduct_config('CATEGORY_NAME','',''))='XYZ'
SELECT * FROM TABLE1 T1
INNER JOIN TABLE2
ON (fn(T1.Blahblah)==1 AND /*other conditions*/)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.