• I tried posting the hard way to do it but can't from here. So, replace the call to dbo.GetInvoiceIDFromBillID with the following to see what I did, just for S & G's.

    right(left(BillID,

    case when charindex('-',BillID) > 0

    then charindex('-',BillID) - 1

    else len(BillID)

    end), len(left(BillID,case when charindex('-',BillID) > 0

    then charindex('-',BillID) - 1

    else len(BillID)

    end)) - patindex('%[0-9]%', left(BillID,case when charindex('-',BillID) > 0

    then charindex('-',BillID) - 1

    else len(BillID)

    end)) + 1)