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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 DateAdd from Max Date Value Column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

24 Posts

Posted - 01/08/2014 :  13:48:57  Show Profile  Reply with Quote
Hey Everyone,

I am trying to generate a @StartDate and @EndDate. The @StartDate would be the 1st of January and the year is dependent on the @EndDate. The @EndDate would be
select max(DateValue) from dbo.testtable

The column DateValue in the testtable contains dates such as 2013-12-09, 2013-12-15.

What I am trying to accomplish is if the @EndDate is populated by select max(DateValue) from dbo.testtable returns '2013-12-15' as the max(DateValue). I want the @StartDate to '2013-01-01' because the year of the EndDate is 2013.

So something along the lines of
@StartDate = DateAdd(yy,?,@EndDate)

Any suggestions?

In (Som, Ni, Yak)

17689 Posts

Posted - 01/08/2014 :  21:16:31  Show Profile  Reply with Quote

@StartDate = DATEADD(YEAR, DATEDIFF(YEAR, 0, @EndDate), 0)

Time is always against us

Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 01/09/2014 :  07:12:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
More querying on datetime columns


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000