July 28, 2010 at 12:17 pm
OK, it's been a while since I've worked in tsql and I'm not even sure if this is doable. We run monthly queries against a third-party database to retrieve monthly data. The between statement includes from the 15th of the prior month to through the 14th of the current month (WHERE CYC_CHG_DTE_OJB BETWEEN '2010-06-15' AND '2010-07-14' format - YYYY-MM-DD). What we are trying to accomplish is to have the year and the month automatically populate based on the date the query is executed/run. For example, if run during the month of September 2010 it should be BETWEEN '2010-08-15' AND '2010-09-14'. Is there an easy way to accomplish this?
July 28, 2010 at 12:21 pm
Edit: I need to learn more about what I'm talking about before posting. :hehe:
July 28, 2010 at 12:26 pm
some useful ideas here to get you started
https://www.sqlservercentral.com/blogs/lynnpettis/archive/2009/03/25/some-common-date-routines.aspx
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
July 28, 2010 at 12:38 pm
I'm looking into dateadd for the year and month.
July 28, 2010 at 1:36 pm
MEH 725 (7/28/2010)
I'm looking into dateadd for the year and month.
select
dateadd(dd,14,dateadd(mm, datediff(mm, 0, GetDate()) - 1, 0)),
dateadd(dd,13,dateadd(mm, datediff(mm, 0, GetDate()), 0))
got me thinking about some of my own reports....this is what I have come up with
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply