vendredi 2 octobre 2020

IF ELSE Not behaving Correctly

I need to write a trigger that limits the hours a user can hit the database and will log the user when they do hit the database. The user is only suppose to login after hours. My problem right now is that my code is kicking the user out regardless of what time they login. Any help I can get is appreciated.

IF((@LOGIN_ID LIKE 'Admin_%')
    AND
   ((DATEPART(HOUR, GETDATE()) BETWEEN 8 AND 16)))
    BEGIN
        ROLLBACK
    END
 
   ELSE IF ((@LOGIN_ID LIKE 'Admin_%')
    AND
  ((DATEPART(HOUR, GETDATE()) BETWEEN 17 AND 24)
    OR
  (DATEPART(HOUR, GETDATE()) BETWEEN 0 AND 7)
  ))

Aucun commentaire:

Enregistrer un commentaire