October 3, 2016 at 12:37 am
This was removed by the editor as SPAM
October 3, 2016 at 1:55 am
EZPZ.
Thanks!
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 3, 2016 at 6:57 am
Thanks Steve. It's a practical one from the category cute quickies QotD.;-)
October 3, 2016 at 8:56 am
The easiest one in a long time. Thanks, Steve!
October 3, 2016 at 9:25 am
Nice one.
Horrible explanation though, unless you provide a definition of "near". Ask yourself whether a thing is near itself - a lot of people would argue that it isn't. Anyway, how is anyone supposed to know that by "near" you mean "less than 1 different from". At least I hope that's what you mean, if it isn't you've got it horrible wrong (eg substitute "not more" for less" in that definition and you'ld be saying ceiling(0) is 1).
Even if you define "near", some people might have trouble with "highest" when applied to negative numbers (just ask any maths teacher how many kigs fail to get it), but in a database context people probably think of "highest" as being related to an order that would be defined by "asc" in an index definition so no problem for the audience here at SQLS Central.
Tom
October 3, 2016 at 10:15 am
TomThomson (10/3/2016)
Nice one.Horrible explanation though, unless you provide a definition of "near". Ask yourself whether a thing is near itself - a lot of people would argue that it isn't. Anyway, how is anyone supposed to know that by "near" you mean "less than 1 different from". At least I hope that's what you mean, if it isn't you've got it horrible wrong (eg substitute "not more" for less" in that definition and you'ld be saying ceiling(0) is 1).
Even if you define "near", some people might have trouble with "highest" when applied to negative numbers (just ask any maths teacher how many kigs fail to get it), but in a database context people probably think of "highest" as being related to an order that would be defined by "asc" in an index definition so no problem for the audience here at SQLS Central.
Fair enough, I'm not sure near is the issue so much as it's the next highest integer that's above the value.
October 3, 2016 at 11:57 am
I've actually used CEILING in my code.
October 3, 2016 at 12:49 pm
Iwas Bornready (10/3/2016)
I've actually used CEILING in my code.
Really. Where? Can you disclose the algorithmic need?
October 3, 2016 at 12:56 pm
Steve Jones - SSC Editor (10/3/2016)
Iwas Bornready (10/3/2016)
I've actually used CEILING in my code.Really. Where? Can you disclose the algorithmic need?
Used it years ago when programmatically adding items to an order using templates. For example, for every three of Item A add one Item B. If there are 1 to 3 of Item A on the order add 1 of Item B, if there are 4 to 6 of Item A add 2 of Item B, etc.
October 4, 2016 at 2:37 am
Steve Jones - SSC Editor (10/3/2016)
Iwas Bornready (10/3/2016)
I've actually used CEILING in my code.Really. Where? Can you disclose the algorithmic need?
I've used it in the last week as well. Trying to split a list into n roughly equal-sized groups
October 4, 2016 at 5:34 am
I've used ceiling (and more frequently, floor) in some remove-time-part-from-datetime operations, pre SQL 2008.
October 8, 2016 at 11:08 am
Lynn Pettis (10/3/2016)
Steve Jones - SSC Editor (10/3/2016)
Iwas Bornready (10/3/2016)
I've actually used CEILING in my code.Really. Where? Can you disclose the algorithmic need?
Used it years ago when programmatically adding items to an order using templates. For example, for every three of Item A add one Item B. If there are 1 to 3 of Item A on the order add 1 of Item B, if there are 4 to 6 of Item A add 2 of Item B, etc.
Another use is an upper bound on the number of tries to guess a number in a known range when each try gets a high, low, or here answer - assuming of course the optimal guessing strategy (binary chop). The highest possible number of guesses (including the correct one) is ceiling(binary log(N)) where N is the number of numbers you start with. There are other worst case computations that use it (and of course best case computations as well).
And it's sometimes useful in costing/purchasing too: If I need to put a length X centimetres steel separator between two parts of an assembly and the separators are sold in lengths which are multiples of y milimetres, and I want the shortest length that I can mill down to do the job (because the cost is proportional to the length) what length do I buy? y*ceiling(x*10/y) millimetres.
And of course the other things already mentioned by other people in this thread. There are plenty of uses for this function.
I haven't actually used it in SQL because I wrote the sort of thing that needs to use ceiling in Fortran or Algol or C or C++ or JavaScript or (long time ago) in one assembly language or another - in fact in almost anything other than SQL (almost - I would never want do anything that wanted it in Prolog or Parlog).
Tom
October 9, 2016 at 10:20 am
Anyone want to write a short piece on a couple uses of CEILING? Or a second one on FLOOR? These would be good items to help someone understand the function(s) better.
November 2, 2016 at 10:20 am
knew the answer but can't ever recall using it!
- Damian
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply