Hi, i'm playing around with building a sql function that will extract numbers from a title, which is what the following code below does. Although, i want to modify this function to parse numbers into sections. For example:
Current Data in title field:
QW 1 RT 309-23-1 QW 1 RT 29-1 QW 1 RT 750-1 QW RT 750-1
Temp tables created once function is ran on title field:
column 1 Column 2 Column 3 Column 4 1 309 23 1 1 29 1 Null 1 750 1 Null Null 750 1 Null
create function [dbo].[ExtractNumbers](@Numbers nvarchar(2000))
returns nvarchar(2000)
as
BEGIN
declare @NonNumericIndex int
set @NonNumericIndex = PATINDEX('%[^0-9]%',@Numbers)
WHILE @NonNumericIndex > 0
begin
SET @Numbers = REPLACE(@Numbers,SUBSTRING(@Numbers,@NonNumericIndex,1),'')
SET @NonNumericIndex = PATINDEX('%[^0-9]%',@Numbers)
SET
end
return @Numbers
END