0

I have a procedure, running every day, to tell me which payments have to be made 7 days from today. I encountered a problem, and I have not discovered how to fix it. If a payment date is set to be made 7 days from a Saturday or a Sunday, I will not have any results.

SELECT CONCAT(' ',CONVERT(date, pdata),' '),
       CONCAT(' ',adoc,' '), 
       CONCAT(' ',nome,' '), 
       CONCAT(CONVERT (money, etotal), '  €'), 
       aprovado  
FROM xxx.dbo.fo
WHERE aprovado like '0' 
  and pdata between DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) 
  and DATEADD(day, 7, GETDATE())

what I need is, the Monday after that weekend (where eventually the payment is set to be made) get the results in this select.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
questionador
  • 111
  • 1
  • 3
  • 12
  • 1
    Please edit your question to include a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). You can do this by adding some sample schema and sample data that reproduces the issue. – AlwaysLearning Jul 13 '20 at 11:40
  • If you wan't to know what day of the week it is you can look at https://stackoverflow.com/questions/1110998/get-day-of-week-in-sql-server-2005-2008 – Preben Huybrechts Jul 13 '20 at 11:50
  • when the job runned today, it returned the results of monday next week. last friday, when the job runned, it returned the results of next friday. yesterday (sunday) and the day before (saturday), the job did not run, so i dont know if i have payments to make next saturday or sunday. what i need is, on mondays, see if there are any results on saturday or sunday before – questionador Jul 13 '20 at 12:46
  • 1
    Something does not match here - perhaps you made an assumption and are looking at the wrong logic? You first said "running every day" yet you added "did not run". But your query selects rows where pdata is between Jan 1 2020 and (ignoring the logic of aprovado) - so it seems you have no rows to select for those days? – SMor Jul 13 '20 at 12:59
  • @SMor OMG, you are so right... i really don't have a problem, just didnt have any results to be returned by the select. Thanks mate!!! – questionador Jul 13 '20 at 13:49

0 Answers0