Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


EOMONTH - 1


EOMONTH - 1

Author
Message
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16443 Visits: 13202
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 SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8321 Visits: 11554
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
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16443 Visits: 13202
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 :-D
(apparently I do have the time to hunt them all down down :w00tSmile

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 SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10704 Visits: 12001
Good to see another 2012 question. I hadn't read about Eomonth before, so had to read a BoL page and learn something new. Cool

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 :-D).

Tom

Thomas Abraham
Thomas Abraham
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2333 Visits: 2254
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
david.irvine 7489
david.irvine 7489
Right there with Babe
Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)

Group: General Forum Members
Points: 745 Visits: 1480
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.
Dana Medley
Dana Medley
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2304 Visits: 1689
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!
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16550 Visits: 17004
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)
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10704 Visits: 12001
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

Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8321 Visits: 11554
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search