2

Hi i am trying to write a query but I am unsure on how to do it. This is the scenario, i want to bring back records which were inserted into the database 30 minutes BEFORE the start of a specific time and 2 hours AFTER. This is what my query looks like;

SELECT  Comment.AddDate,Event.StartTime
FROM Comment
JOIN Users on Users.USERS_ID  = Comment.UserID
JOIN Event ON Users.USERS_ID = Event.UserID
WHERE EventID = 5630

Now from the above i need records which Comment.AddDate was entered 30 minutes before Event.StartTime and 2 hours later. How do i go about doing this?

1 Answer 1

3
SELECT Comment.AddDate, Event.StartTime
  FROM Comment
  JOIN Users ON Users.USERS_ID = Comment.UserID
  JOIN Event ON Users.USERS_ID = Event.UserID
 WHERE EventID = 5630
   AND Comment.AddDate BETWEEN DATEADD(minute, -30, Event.StartTime)
       AND DATEADD(hour, 2, Event.StartTime)

Documentation located here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.