Friday, October 11 2024

Day: December 11, 2021

How to extract alpha or numbers from a string within a SELECT statement WITHOUT a function call

I am using the following SQL to create a function to strip out characters or numbers. CREATE FUNCTION [dbo].[fn_StripCharacters] ( @String NVARCHAR(MAX), @MatchExpression VARCHAR(255) ) RETURNS NVARCHAR(MAX) AS BEGIN SET @MatchExpression = ‘%[‘+@MatchExpression+’]%’ WHILE PatIndex(@MatchExpression, @String) > 0 SET @String = Stuff(@String, PatIndex(@MatchExpression, @String), 1, ”) RETURN @String END I am calling it like this […]