如果值存在连接表,则为条件连接

时间:2013-11-26 05:19:08

标签: sql sql-server join

我有一个名为level_2_tags的表,如果用户选择了二级标记我希望它通过内部联接加入另一个表,否则我希望它加入左连接

IF RLT ID EXISTS BELOW METHOD 
SELECT  RMC.* INTO #TTEMP   
FROM    #TRestrictedMainCatagory RMC
    JOIN #TRestrictedAssetType RAT
        ON RMC.ID = RAT.ID  
    JOIN #TRestrictedLevelTwo RLT
        ON RLT.ID=RAT.ID

ELSE 
     SELECT RMC.* INTO #TTEMP   
FROM    #TRestrictedMainCatagory RMC
    JOIN #TRestrictedAssetType RAT
        ON RMC.ID = RAT.ID  
    LEFT OUTER JOIN #TRestrictedLevelTwo RLT
        ON RLT.ID=RAT.ID

请帮我解决此事

0 个答案:

没有答案