mister.magoo (10/9/2015)
Lynn Pettis (10/9/2015)
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)
^-- This.
Or this?
SUBSTRING( LEFT( BillID, ISNULL( NULLIF( charindex('-',BillID), 0) - 1, 20)), PATINDEX( '%[0-9]%', BillID), 20)