简体   繁体   中英

How to use join in a case statement

Code below is not working. I want to pull the BatchHorizon of the corresponding PACKAGE. I cannot directly use "then BatchHorizon " since the batchhorizon is inside the subquery.

Case When PACKAGE IN (SELECT DISTINCT PACKAGE
                      FROM BATCHINGWINDOW AS A
                     ) 
     Then (SELECT  BatchHorizon
           FROM BATCHINGWINDOW AS B 
           WHERE B.PACKAGE = A.PACKAGE
         )
     else 3
 end
select 

Case When O.PACKAGE IN (SELECT PACKAGE
                      FROM BATCHINGWINDOW  
                     ) 
     Then (SELECT  DISTINCT BatchHorizon
           FROM BATCHINGWINDOW AS B 
           WHERE B.PACKAGE = O.PACKAGE
         )
     else 3
 end pack
 from table O

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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