SELECT DISTINCT FC.LM_ACT_ID , FC.LM_FCLTY_ID , FC.LM_ROOM_ID , LM_SS_FCLTY_DISP FROM PS_LM_SES_VW FC WHERE EXISTS ( SELECT SS.LM_ACT_ID FROM PS_LM_SES SS WHERE FC.LM_ACT_ID = SS.LM_ACT_ID AND SS.LM_FCLTY_ID > 0 AND SS.LM_SES_DT = ( SELECT MAX(X.LM_SES_DT) FROM PS_LM_SES X WHERE SS.LM_ACT_ID = X.LM_ACT_ID AND SS.LM_LC_ID = X.LM_LC_ID AND SS.LM_SES_ID = X.LM_SES_ID AND X.LM_SES_DT <= %CurrentDateIn) GROUP BY SS.LM_ACT_ID HAVING COUNT(DISTINCT SS.LM_FCLTY_ID) = 1 ) UNION SELECT DISTINCT FC.LM_ACT_ID , 9999999999 , 9999999999 , 'Y' FROM PS_LM_SES_VW FC WHERE EXISTS ( SELECT SS.LM_ACT_ID FROM PS_LM_SES SS WHERE FC.LM_ACT_ID = SS.LM_ACT_ID AND SS.LM_FCLTY_ID > 0 AND SS.LM_SES_DT = ( SELECT MAX(X.LM_SES_DT) FROM PS_LM_SES X WHERE SS.LM_ACT_ID = X.LM_ACT_ID AND SS.LM_LC_ID = X.LM_LC_ID AND SS.LM_SES_ID = X.LM_SES_ID AND X.LM_SES_DT <= %CurrentDateIn) GROUP BY SS.LM_ACT_ID HAVING COUNT(DISTINCT SS.LM_FCLTY_ID) > 1 )
|