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 ««123»»

EOMONTH - 1 Expand / Collapse
Author
Message
Posted Monday, January 21, 2013 2:53 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:02 PM
Points: 13,539, Visits: 11,342
Sean Pearce (1/21/2013)

Since when did SQL Server start copying Excel?


Since SQL Server 2012 apparently

Other functions "stolen" from other languages: choose, iif, format and concat




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1409447
Posted Monday, January 21, 2013 2:53 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 3:56 PM
Points: 6,086, Visits: 8,354
Sean Pearce (1/21/2013)
Since when did SQL Server start copying Excel?

It didn't (at least not the buggy version of the code that was distributed in Excel 97 and Excel 98 for Macintosh). But in SQL Server 2012, there are definitely a lot of new function that are totally useless - except if you want to enable an easier transition from VBA and Access SQL to T-SQL. EOMONTH is one of them, IIF is a very clear example, and I think there were a few more, but I don't have the time to hunt them all down now.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1409448
Posted Monday, January 21, 2013 3:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:02 PM
Points: 13,539, Visits: 11,342
Hugo Kornelis (1/21/2013)
EOMONTH is one of them, IIF is a very clear example, and I think there were a few more, but I don't have the time to hunt them all down now.


I listed them at the same time you posted
(apparently I do have the time to hunt them all down down )

Most of the new TSQL functions are usability functions, in the sense that you could achieve the same in earlier versions of SQL Server, but with a more clever use of existing functions, such as dateadd.

Notable exceptions are OFFSET and FETCH, and the new windowing functions, which are awesome by the way.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1409458
Posted Monday, January 21, 2013 4:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:47 AM
Points: 7,855, Visits: 9,603
Good to see another 2012 question. I hadn't read about Eomonth before, so had to read a BoL page and learn something new.

It's mildly irritating though, having to work out what days of the week are 29 Feb 2016 and 31 Dec 2016 - the sort of thing that would tempt me to run the code if the version of of SQL Server I have (2008 R2) included Eomonth.

edit: Like Koen, I assumed that the new function wouldn't be screwed up - after all, the date handling in earler versions recognised leap years OK, why would this new function in 2012 be different? (I wasn't aware of teh EXCEL function - so maybe that was an easier choice for me than for Koen ).


Tom
Post #1409488
Posted Monday, January 21, 2013 5:14 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 10:03 AM
Points: 1,895, Visits: 2,194
Sean Pearce (1/21/2013)
This question is better suited for www.GeographyCentral.com.

How does knowing the last day of February in 2016 have anything to do with SQL Server? I had to check a calendar in order to answer this question, books online was no good here.



It would be sad if there was ever a book called, "Everything I Needed to Know I Learned in BOL"!


Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Post #1409502
Posted Monday, January 21, 2013 5:31 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 9:55 AM
Points: 396, Visits: 866
Sean Pearce (1/21/2013)
Stewart "Arturius" Campbell (1/21/2013)
Good qurstion, Ron,
Thanks

Sean Pearce (1/21/2013)
This question is better suited for www.GeographyCentral.com.

How does knowing the last day of February in 2016 have anything to do with SQL Server? I had to check a calendar in order to answer this question, books online was no good here.



Point of note:
The EOMONTH function in Excel currently does not recognise leap years. Therefore, if this was an exact copy of the function as used in Excel, it would not work correctly.

Since when did SQL Server start copying Excel?


The link you provided says that this was only a problem for century years not divisible by 400 (so 1900, 2100 etc.) So the Excel formula would have given the correct answer to this question. It also says that the error was fixed in Excel 2000.
Post #1409505
Posted Monday, January 21, 2013 7:41 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, November 21, 2014 1:23 PM
Points: 1,951, Visits: 1,473
I'd never heard of this function, so it was good to hear and learn about it. I have never of this function (not even in Excel since I don't use it that much), so much like Koen and Tom I went into this under the impression that they hadn't screwed up a new function to use.

Thank you very much for the great question on a new 2012 feature.




Everything is awesome!
Post #1409553
Posted Monday, January 21, 2013 7:44 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:54 PM
Points: 13,228, Visits: 12,705
Had not heard about this function until now. Like others I assumed they got it right. The question actually pretty much answers itself. The first 3 sets of choices are all pretty much the same thing. If the function got the leap year right or wrong will provide those. The last couple options seemed like a no brainer to me because the implicit date conversion would not be any different in a function than anywhere else and if the conversion had failed none of the rest of the answers would have even been possible. Given that, there were 8 choices and we were told there were 4 possible answers it all came down to a coin-toss...does the function correctly recognize leap years or not.

Good question and it is great to learn about new stuff in 2012!!!


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1409557
Posted Monday, January 21, 2013 7:52 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:47 AM
Points: 7,855, Visits: 9,603
Hugo Kornelis (1/21/2013)
... But in SQL Server 2012, there are definitely a lot of new function that are totally useless - except if you want to enable an easier transition from VBA and Access SQL to T-SQL. EOMONTH is one of them, IIF is a very clear example, and I think there were a few more, but I don't have the time to hunt them all down now.

I take a different view of Eomonth: anything that makes the developer's life easier is a useful function. It is a lot easier to write EOMONTH(somedate)
for example than to write cast(DATEADD(DAY,-DATEPART(DAY,somedate),DATEADD(MONTH,1,somedate)) AS DATE).
A developer is unlikely to get an EOMONTH call wrong, and you can't say the same for a construction of the same function from datepart and dateadd. It's also a lot easier to read the Eomonth call, to see instantly what it means, and hence to debug and maintain and enhance - so there is a lot of real business value in that function.
It would have saved me some pain if my people could have used something like EOMONTH back in the days of SQL Server 2000. And since we were a shop where the scripting language was JScript not VBA that wasn't because people were converting anything which already used an EOMONTH function.

Maybe some of the other functions are a bit useless, though.


Tom
Post #1409562
Posted Monday, January 21, 2013 8:18 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 3:56 PM
Points: 6,086, Visits: 8,354
L' Eomot Inversé (1/21/2013)
Hugo Kornelis (1/21/2013)
... But in SQL Server 2012, there are definitely a lot of new function that are totally useless - except if you want to enable an easier transition from VBA and Access SQL to T-SQL. EOMONTH is one of them, IIF is a very clear example, and I think there were a few more, but I don't have the time to hunt them all down now.

I take a different view of Eomonth: anything that makes the developer's life easier is a useful function. It is a lot easier to write EOMONTH(somedate)
for example than to write cast(DATEADD(DAY,-DATEPART(DAY,somedate),DATEADD(MONTH,1,somedate)) AS DATE).
A developer is unlikely to get an EOMONTH call wrong, and you can't say the same for a construction of the same function from datepart and dateadd. It's also a lot easier to read the Eomonth call, to see instantly what it means, and hence to debug and maintain and enhance - so there is a lot of real business value in that function.
It would have saved me some pain if my people could have used something like EOMONTH back in the days of SQL Server 2000. And since we were a shop where the scripting language was JScript not VBA that wasn't because people were converting anything which already used an EOMONTH function.

Maybe some of the other functions are a bit useless, though.

My main issue with EOMONTH is that it's a lost opportunity to do something *really* useful, and a whole bunch of future forum questions.
It's just too compelling to write "WHERE MyDateColumn BETWEEN *something to calculate the first day of the current month* AND EOMONTH(getdate())" - but that would in many cases not return the correct results. EOMONTH always returns the last day of the month with time 0:00, so if my data stores time as well, I lose all events on the last day. For regular datetime data, I would want a function to return 23:59:59.997; for smalldatetime 23:59; for datetime2(7) 23:59:59.9999999, and for my specific data that is constrained to store only whole hours I want 23:00.

So for me, a far better choice would have been to implement a BOMONTH (for the first day of the month - though one can wonder how much this simplifies life, as the first of the month is pretty easy to get anyway) and then use a DATEDIFF to subtract 3ms, 1 second, 100 ns, or an hour.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1409577
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse