Extract currency values from text with T-SQL
CREATE FUNCTION dbo.fnGetAmounts(@str nvarchar(max)) RETURNS TABLE AS RETURN ( -- generate all possible starting positions ( 1 to len(@str)) WITH StartingPositions AS ( SELECT 1 AS Position UNION ALL SELECT Position+1 FROM StartingPositions WHERE Position <= LEN(@str) ) -- generate all possible lengths , Lengths AS ( SELECT 1 AS [Length] UNION ALL SELECT [Length]+1 FROM Lengths WHERE [Length] <= 15 ) -- a Cartesian product between StartingPositions and Lengths -- if the substring is numeric then get it ,PossibleCombinations AS ( SELECT CASE WHEN ISNUMERIC(substring(@str,sp.Position,l.Length)) = 1 THEN substring(@str,sp.Position,l.Length) ELSE null END as Number ,sp.Position ,l.Length FROM StartingPositions sp, Lengths l ...