Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need to pull data since last November(year change)

Author  Topic 

jaimealvarez
Starting Member

31 Posts

Posted - 2014-08-20 : 15:50:25
Hi I have to pull data for a report from 11/1/2013 to date. But once we get to 11/1/2014 then the report should pull data from 11/1/2014 to date and so on. Is there a way to do this? I guess I could go in and change the year manually but was hoping that there was a way to do this autmoatically.

so today would be
tadate >= '11/1/2013'

but at any point between 11/1/2014 to 10/31/2015 it should be
tadate >= '11/1/2014'

and so on...

Thank you!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-08-20 : 15:56:59
where tadate >= '11-01-' + convert(char(4), year(getdate())-1)

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-08-20 : 16:13:16
Shouldn't this be (see red)
quote:
Originally posted by tkizer

where tadate >= '11-01-' + convert(char(4), year(dateadd(mm,2,getdate()))-1)

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-08-20 : 16:26:15
quote:
Originally posted by bitsmed

Shouldn't this be (see red)
quote:
Originally posted by tkizer

where tadate >= '11-01-' + convert(char(4), year(dateadd(mm,2,getdate()))-1)





Yep. I forgot about the November/December issue.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jaimealvarez
Starting Member

31 Posts

Posted - 2014-08-20 : 16:55:43
Thank you both!
Go to Top of Page
   

- Advertisement -