0

Hi i am looking for a query that can give me notification for sale orders i made after 30 days from order date and show the notification for 4 days and disappear after that

for example if i have made sale order on 2016-01-19 after adding 30 days my start date will be 2016-02-18 and adding 4 days to current date my end date will be 2016-02-23'

i have tried to do that using the below query but it dose not give the desired out put which is records between 2016-02-18 and 2016-02-23

output i get from below query is empty

select * from [dbo].[Orders] where [OrderDate] between Dateadd(d, 30, OrderDate) and Dateadd(d, 4, GETDATE())
5
  • 1
    but it dose not give the desired out put --> What does that mean? What did you expect and what did you get instead. Please add some sample data. Commented Feb 19, 2016 at 8:07
  • i suppose to get records between 2016-01-19 and 2016-02-23 but the output i get is empty Commented Feb 19, 2016 at 8:11
  • I'm not following your logic - find me rows where X is between X+30 and (some even greater value). How is that ever meant to work? You're obviously thinking of two separate OrderDate values here but I'm not sure where they come from. Commented Feb 19, 2016 at 8:15
  • Damien_The_Unbeliever can u help with correct logic then i just need reminder to show me records i made after 30 days from creation date and disappear after x numbers of days Commented Feb 19, 2016 at 8:22
  • Sorry but this does not seem to work [OrderDate] between Dateadd(d, 30, OrderDate) I'm afrade a value cannot be greater itself Commented Feb 19, 2016 at 8:28

1 Answer 1

3

I think that you're trying to find orders that occurred between 30 and 34 days ago:

select * from [dbo].[Orders]
where [OrderDate] between Dateadd(day, -34, GETDATE()) and
                          Dateadd(day, -30, GETDATE())

You may wish to adjust these values somewhat, especially if your OrderDate values include times also, and because GETDATE() values always include time.

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.