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
 how to set the @fromdate to start of the year

Author  Topic 

gagani
Posting Yak Master

112 Posts

Posted - 2012-10-25 : 05:38:51
I want to set the @fromdate to start of the year , that is 2012-01-01 00:00:00 if the given from date is belonging to this year

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-10-25 : 05:43:54
If datediff(yy,@fromdate,getdate()) = 0
select @fromdate = dateadd(yy,datediff(yy,0,fromdate),0)

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -