• Michael L John (10/8/2015)


    SQLPain (10/8/2015)


    For the this year Funded, approved, etc the following where statement should work correct?

    WHERE c2.DateContractFunded >= dateadd(yy, 0, DATEADD(yy, DATEDIFF(yy, 0, getdate()), 0))

    Yes. Look at your code for to get last year. It's the same thing, except you are not adding -1 to the year.

    Break each of the parts down and learn what each does.

    SELECT getdate() = Returns the current data and time.

    SELECT DATEDIFF(yy, 0, getdate()) = Returns the number of years between 0 (which translates to 1900-01-01 00:00:00.000) and now. 115

    SELECT DATEADD(yy, DATEDIFF(yy, 0, getdate()), 0) = Adds 115 to 1900-01-01 00:00:00.000, which gives you 01-01-2015 00:00:000

    SELECT dateadd(yy, 0, DATEADD(yy, DATEDIFF(yy, 0, getdate()), 0)) = Adds nothing to the above answer. Not really needed for this.

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/