委外入貨單項次在原單據下
委外入貨單項次在原單據下未退貨過的 但是不可包括本筆
委外入貨單項次.委外入貨單_ID=@原單據_ID@
AND
EXISTS(SELECT 1 FROM 品管狀態 b WHERE b.名稱='驗退' AND 委外入貨單項次.品管狀態_ID=b.品管狀態_ID) AND NOT EXISTS (SELECT 1 FROM 委外入貨單項次 a WHERE a.原項次_ID=委外入貨單項次.委外入貨單項次_ID AND 委外入貨單項次.委外入貨單項次_ID<>@原項次_ID@ )
委外入貨單項次.訂單_ID=@訂單_ID@ AND (@原單據_ID@=0 OR 委外入貨單項次.委外入貨單_ID=@原單據_ID@)
AND EXISTS(SELECT 1 FROM 品管狀態 b WHERE b.名稱='驗退' AND 委外入貨單項次.品管狀態_ID=b.品管狀態_ID) AND NOT EXISTS (SELECT 1 FROM 委外入貨單項次 a WHERE a.原項次_ID=委外入貨單項次.委外入貨單項次_ID AND 委外入貨單項次.委外入貨單項次_ID<>@原項次_ID@ )
沒有留言:
張貼留言