• Good work. Most certainly there are cases when a string - or bigint - needs to be constructed this way.

    Otherwise, of course, just the 112 format mask for CONVERT will produce a string that can be further cast as int.

    A word of advice about UDF usage (this one being a tempting candidate!):

    - indiscriminate use of the function will slow down queries and may end up in a limbo during multiple selects in views. The native CONVERT function is preferable (where a YYYYMMDD value is sufficient).

    - use in stored procs is preferable, as a CONST before processing (avoid using it in-line)