Vimal Lohani (8/13/2014)
Thanks ChrisM@Work for your comment. I got the tone.Generally UDFs are slow as compare to same query.
You may also wish to correct the error. Your function returns incorrect values when the time of the from-date is later than the time of the to-date - use the dates from my last post to check. Changing the input parameters to DATE might fix this - it's worth a try.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden