• You are right about the systax errors, it was happening as I had some empty characters in the query I attached. I am reattaching the script w/o the empty characters.

    Also, to note that this script is compatible only with SQL Server 2005 versions or newer.

    Thanks