• 1) Yep - that's a scalar UDF alright 😀

    2) At least it doesn't have ancillary data access!

    3) Looks like some kind of funky iterative logic that might be able to take advantage of a Numbers table

    4) How is it used in the query? If in the WHERE clause you are pretty much guaranteed to be hosed.

    5) I wonder if a persisted calculated column would be workable here...

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service