Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Finding New Years Eve Expand / Collapse
Author
Message
Posted Monday, December 31, 2012 9:50 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 3:05 PM
Points: 31,284, Visits: 15,750
Comments posted to this topic are about the item Finding New Years Eve






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1401545
Posted Monday, December 31, 2012 9:53 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, September 18, 2014 2:30 AM
Points: 595, Visits: 219
Thanks Steve for the new year gift. And Happy new year for entire "sqlservercenter" family..
Post #1401546
Posted Monday, December 31, 2012 10:30 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, May 18, 2014 4:48 PM
Points: 422, Visits: 74
Thanks Steve for the good question on new year.

Happy new year for everyone...
Post #1401549
Posted Tuesday, January 1, 2013 12:48 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 5:23 AM
Points: 1,409, Visits: 1,316
Happy New Year



See, understand, learn, try, use efficient
© Dr.Plch
Post #1401559
Posted Tuesday, January 1, 2013 3:38 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 2:31 AM
Points: 1,109, Visits: 306
Just to be picky, it actually won't work after the 28th Jan due to that dateadd of a month in there

Happy new year

Kev


-------------------------------
Oh no!
Post #1401568
Posted Tuesday, January 1, 2013 4:14 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, October 16, 2014 10:02 AM
Points: 1,372, Visits: 1,566
Happy New Year to all

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1401569
Posted Tuesday, January 1, 2013 4:38 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:21 AM
Points: 6,098, Visits: 8,367
Kevin Gill (1/1/2013)
Just to be picky, it actually won't work after the 28th Jan due to that dateadd of a month in there

And to be even more picky, all three answer options have a mismatch in the parentheses. Here is the corrected version:
-- select 1
SELECT dateadd(day,-(datepart(day,dateadd(mm,1,GETDATE()))),dateadd(mm,-1,GETDATE()))
-- select 2
SELECT dateadd(day,-(datepart(day,dateadd(mm,1,GETDATE()))),GETDATE())
-- select 3
SELECT dateadd(day,-(datepart(day,dateadd(mm,1,GETDATE()))),dateadd(mm,1,GETDATE()))

And for those who prefer to use efficient code to get the last day of the previous month, use either one of these options:
-- Option 1
SELECT dateadd(day, -datepart(day, getdate()), getdate());
-- Option 2
SELECT dateadd(month, datediff(month, getdate(), '20110101'), '20101231');

Option 2 has the additional advantage that you get only the day; all other options include a time part.

(None of this is intended as criticism of a question, just to provide some additional information).



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1401570
Posted Tuesday, January 1, 2013 4:39 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:21 AM
Points: 6,098, Visits: 8,367
(deleted)


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1401571
Posted Tuesday, January 1, 2013 5:17 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 24, 2014 10:38 AM
Points: 1,165, Visits: 548
I also noted the missing parentheses as well. I believe that adding a month before getting the day was simply a red herring to throw you off, but as stated previously it won't work for the entire month of January because February doesn't have 31 days in it! In any case, it was a good thought exercise!!


"...when ye are in the service of your fellow beings ye are only in the service of your God." -- Mosiah 2:17
Post #1401579
Posted Tuesday, January 1, 2013 7:45 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Monday, November 24, 2014 8:49 AM
Points: 662, Visits: 966
is it me the only one who finds all answers wrong as there's a missing parenthesis in all of them??

depends on where you place the missing one in 'select 2' you get the right answer or syntax error which is kinda common tricky answer for a QotD...

Post #1401599
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse