I want a query where I need to take all results where the date is between current and a year ago. So if the query is track tomorrow, the results are successful to be a little bit unlike than they were if it was run today. If I run this today, it would essentially be like saying "where the date is between 6/1/2014 and 6/6/2016." Tomorrow, between 6/2/2014 and 6/7/2016, and so on.
I could setup it just the similar as a regular WHERE clause concerning dates. Code is
WHERE CreateDate BETWEEN (DATEADDS(Year,-1,GETDATE()) AND (GetDATE())
First, I'm not sure if the DATEADDS() part is what I should use -- I just tried it depends on what I was read on another forum. I've got a red wavy telling me I've got a syntax fault near AND.
Can anyone solve my issue?
How to create a query from current date to and a year ago?
-
- Posts: 1
- Joined: Mon May 30, 2016 2:52 am
- VueSoft
- Dan Chartrand
- Posts: 3893
- Joined: Sat Aug 23, 2008 12:39 am
- Location: St. Louis, Missouri, USA
- Contact:
Re: How to create a query from current date to and a year ag
Hi kokilasoral, welcome to the forums. Is your question related to VueMinder, or SQL syntax in general? VueMinder doesn't provide an interface for direct SQL queries.
Also, SQL syntax can vary depending on the database system you're using. Here's my best guess...
Also, SQL syntax can vary depending on the database system you're using. Here's my best guess...
Code: Select all
SELECT * FROM MyTable WHERE CreateDate BETWEEN CURDATE() - INTERVAL 1 YEAR AND CURDATE()
Dan Chartrand, Founder
VueSoft LLC | St. Louis, Missouri, USA
VueSoft LLC | St. Louis, Missouri, USA
Re: How to create a query from current date to and a year ag
Try the below option, it may help you to find the answer.
CONCAT(<enter date i.e. yyyymm>, '01') AS Date_SK
Answer resource: a training on the concepts of SQL from a well experienced trainer from intellipaat made me to find answers to the particular question.
CONCAT(<enter date i.e. yyyymm>, '01') AS Date_SK
Answer resource: a training on the concepts of SQL from a well experienced trainer from intellipaat made me to find answers to the particular question.