Guest User

Untitled

a guest
Sep 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --I need to get background checks that are going to expire in 30 days from the current day, but don't already have a newer one of that type.
  2.  
  3. SELECT bg_check_id ,
  4.     provider_id ,
  5.     check_type ,
  6.     upload_id ,
  7.     who_approved ,
  8.     notes ,
  9.     approval_date ,
  10.     started_date ,
  11.     status FROM  (SELECT *
  12.         FROM providers_background_checks
  13.         WHERE status = 'approved'
  14.         AND approval_date >= '2011-09-13 00:00:00.0'
  15.         ORDER BY approval_date  desc) as subq
  16.     WHERE approval_date >= '2011-09-13 00:00:00.0'
  17.     AND approval_date <= '2011-09-13 23:59:59.9999'
  18.     AND (check_type, provider_id) NOT IN(SELECT check_type, provider_id
  19.         FROM providers_background_checks
  20.         WHERE approval_date > '2011-09-13 00:00:00.0')
Add Comment
Please, Sign In to add comment