• Jeff, your solution works better, thanks.

    I am using Microsoft SQL Server Management Studio 10.50.2500.0, @@version:

    Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)

    Jun 17 2011 00:54:03

    Copyright (c) Microsoft Corporation

    Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)

    I have no problem creating the function (maybe I changed something somewhere sometime, but don't know anymore :hehe: ).