Home Between dynamic dates

# Between dynamic dates

kazzi
1#
kazzi Published in 2017-11-13 19:15:43Z
 So part of my query, I would like to filter the results to show just the ones between a set date range, however, that date range is dynamic, based on an event. For example: WHERE date d BETWEEN '2017-01-01' -- just a sample fixed date AND DATEADD(D, CONTACT_DATE, -1) -- to show a day before Contact Date  Basically just trying see if there was another CONTACT_DATE this year, excluding the day of the actual contact. I know there could be other ways to do this, but I was wondering if I can tweak a query with the current logic. ERROR: Argument data type datetime is invalid for argument 2 of dateadd function.
dns_nx
2#
 You mixed the parameters. The syntax is this: DATEADD (datepart , number , date )  You should change it to this: DATEADD(D, -1, CONTACT_DATE)  See here the docs: https://msdn.microsoft.com/de-de/library/ms186819(v=sql.120).aspx
 It should be: DATEADD(D, -1, CONTACT_DATE)