简体   繁体   English

当条件为true时,内部连接进入sql server

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM