code_junkie

SQL query question: SELECT … NOT IN

Nov 12th, 2011
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. SELECT idCustomer FROM reservations
  2. WHERE idCustomer NOT IN
  3. (SELECT distinct idCustomer FROM reservations
  4. WHERE DATEPART ( hour, insertDate) < 2)
  5.  
  6. SELECT idCustomer FROM reservations
  7.  
  8. SELECT distinct idCustomer FROM reservations
  9. WHERE DATEPART ( hour, insertDate) < 2
  10.  
  11. SELECT distinct idCustomer FROM reservations
  12. WHERE DATEPART ( hour, insertDate) < 2
  13. and idCustomer is not null
  14.  
  15. WHERE field1 NOT IN (1, 2, 3, null)
  16.  
  17. WHERE NOT (field1 = 1 OR field1 = 2 OR field1 = 3 OR field1 = null)
  18.  
  19. IF 1 NOT IN (1, 2, 3, NULL) PRINT '1 NOT IN (1, 2, 3, NULL)'
  20. IF 1 NOT IN (2, 3, NULL) PRINT '1 NOT IN (2, 3, NULL)'
  21. IF 1 NOT IN (2, 3) PRINT '1 NOT IN (2, 3)' -- Prints
  22. IF 1 IN (1, 2, 3, NULL) PRINT '1 IN (1, 2, 3, NULL)' -- Prints
  23. IF 1 IN (2, 3, NULL) PRINT '1 IN (2, 3, NULL)'
  24. IF 1 IN (2, 3) PRINT '1 IN (2, 3)'
  25.  
  26. SELECT idCustomer FROM reservations
  27. EXCEPT
  28. SELECT idCustomer FROM reservations WHERE DATEPART ( hour, insertDate) < 2
  29.  
  30. SELECT Reservations.idCustomer FROM Reservations (nolock)
  31. LEFT OUTER JOIN @reservations ExcludedReservations (nolock) ON Reservations.idCustomer=ExcludedReservations.idCustomer AND DATEPART(hour, ExcludedReservations.insertDate) < 2
  32. WHERE ExcludedReservations.idCustomer IS NULL AND Reservations.idCustomer IS NOT NULL
  33. GROUP BY Reservations.idCustomer
Add Comment
Please, Sign In to add comment