This is actually a follow-up question to a topic mentioned here: split alpha and numeric using sql Facing similar problems, I adjusted @knkarthick24 (a chance to say tnx!) query to my needs almost perfectly (I have “2,500” not “2 500”) as follow:
SELECT [Quantity]
,substring(replace(subsrtunit, ',', ''), PATINDEX('%[0-9.]%', replace(subsrtunit, ',', '')) + 1, len(subsrtunit)) AS unit
,LEFT(replace(subsrtnumeric, ',', ''), PATINDEX('%[^0-9.]%', replace(subsrtnumeric, ',', '') + 't') - 1) AS num
FROM (
SELECT [Quantity]
,subsrtunit = SUBSTRING([Quantity], posofchar, LEN([Quantity]))
,subsrtnumeric = SUBSTRING([Quantity], posofnumber, LEN([Quantity]))
FROM (
SELECT [Quantity]
,posofchar = PATINDEX('%[^0-9.]%', replace([Quantity], ',', ''))
,posofnumber = PATINDEX('%[0-9.]%', replace([Quantity], ',', ''))
FROM [OPI].[dbo].[MRRInvoices]
WHERE DocumentNum IS NOT NULL
) d
) t
the only thing left is handling negative values.
Right now the results I'm getting for a negative value in Quantity field (-1.00 GB) is (.00 GB) in the unit field and (1.00) for num field.
Also, does anyone know how to "translate" it to derived column in SSIS? Can "Findstring" in SSIS replace PATINDEX?
Thank you all in advance.