SELECT
(CASE WHEN tblItem > tblBOM AND tblItem >tblFSB_TA AND tblItem > tblRev AND tblItem >tblMisc THEN tblItem
WHEN tblBOM > tblFSB_TA AND tblBOM > tblRev AND tblBOM > tblMisc THEN tblBOM
WHEN tblFSB_TA > tblRev AND tblFSB_TA > tblMisc THEN tblFSB_TA
WHEN tblRev > tblMisc THEN tblRev END) AS LUD, DATEDIFF(DAY,GETDATE(),LUD) AS DAYS
FROM tblSynched
|