I've written the following T-SQL function, but on implementation it seems to be very slow (it basically functions to return a phone number from a string such as "01530 999111 - don't phone in the evening!".
Do any of you marvellously insightful people have any tips for me in order to improve the performance of this function or have any more efficient alternatives to suggest?
ALTER FUNCTION [dbo].[xfnJustNumbers](@inStr varchar(255))
RETURNS [varchar](255)
AS
BEGIN
DECLARE @outStr varchar(255)
SELECT @outStr = ''
DECLARE @charNo int
SELECT @charNo = 0
WHILE @CharNo < len(@inStr) begin
SELECT @CharNo = @CharNo +1
IF isnumeric(substring(@inStr,@CharNo,1))=1 SELECT @outStr = @outStr + substring(@inStr,@CharNo,1)
END
RETURN @outStr
END
Thanks :)
WITH SCHEMABINDINGused on scalar UDFs - Not sure if that has any performance benefit at all.IsNumericas that matches things like+,-,$you would useLIKE [0-9]orASCII(@CHR) BETWEEN 48 AND 57