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

时间:2013-11-01 04:56:24

标签: sql sql-server

我希望在某些条件成立时进行内连接

case  
when (select dbo.fnGetProduct_config('CATEGORY_NAME','',''))='XYZ'  
then inner join product_master t12 on t12.id=t1.product_id  
END  

2 个答案:

答案 0 :(得分:5)

您不能使用条件来决定是否加入(动态sql除外),但您可以将谓词添加到连接....

...
from table1
inner join product_master t12 on t12.id=t1.product_id and dbo.fnGetProduct_config('CATEGORY_NAME','',''))='XYZ'

答案 1 :(得分:-1)

SELECT * FROM TABLE1 T1
INNER JOIN TABLE2
 ON (fn(T1.Blahblah)==1 AND /*other conditions*/)