Hi Folks
Just starting out in the world of SQL and am having a problem with dates. I have the following in a table called tblData:
Date,Data
01/01/2004,123123123
01/02/2004,123123123
01/03/2004,123123123
01/04/2004,123123123
01/05/2004,123123123
01/06/2004,123123123
01/07/2004,123123123
01/08/2004,123123123
01/09/2004,123123123
01/10/2004,123123123
01/11/2004,123123123
01/12/2004,123123123
01/01/2005,123123123
01/02/2005,123123123
01/03/2005,123123123
I want to create an SQL query that will return all rows with a date within the last 12 months. So, with the above example, I want to see the following result (taking the current date to be 31/03/2005):
01/03/2004,123123123
01/04/2004,123123123
01/05/2004,123123123
01/06/2004,123123123
01/07/2004,123123123
01/08/2004,123123123
01/09/2004,123123123
01/10/2004,123123123
01/11/2004,123123123
01/12/2004,123123123
01/01/2005,123123123
01/02/2005,123123123
01/03/2005,123123123
I created a query that gives me the current date but am not sure if it helps me with this:
SELECT Today=convert(varchar, GETDATE(), 101)
I also know that DATEDIFF could help but I'm finding it impossible to string all this together into a SQL query that works! Is anyone able to help?
Thanks!
Just starting out in the world of SQL and am having a problem with dates. I have the following in a table called tblData:
Date,Data
01/01/2004,123123123
01/02/2004,123123123
01/03/2004,123123123
01/04/2004,123123123
01/05/2004,123123123
01/06/2004,123123123
01/07/2004,123123123
01/08/2004,123123123
01/09/2004,123123123
01/10/2004,123123123
01/11/2004,123123123
01/12/2004,123123123
01/01/2005,123123123
01/02/2005,123123123
01/03/2005,123123123
I want to create an SQL query that will return all rows with a date within the last 12 months. So, with the above example, I want to see the following result (taking the current date to be 31/03/2005):
01/03/2004,123123123
01/04/2004,123123123
01/05/2004,123123123
01/06/2004,123123123
01/07/2004,123123123
01/08/2004,123123123
01/09/2004,123123123
01/10/2004,123123123
01/11/2004,123123123
01/12/2004,123123123
01/01/2005,123123123
01/02/2005,123123123
01/03/2005,123123123
I created a query that gives me the current date but am not sure if it helps me with this:
SELECT Today=convert(varchar, GETDATE(), 101)
I also know that DATEDIFF could help but I'm finding it impossible to string all this together into a SQL query that works! Is anyone able to help?
Thanks!