I have a question about an alphanumeric chain, I have to validate that this chain if it has an alphanumeric, for example:
EJEMPLO123+
Delete the% "+"
and keep the alphanumeric only.
I have a question about an alphanumeric chain, I have to validate that this chain if it has an alphanumeric, for example:
EJEMPLO123+
Delete the% "+"
and keep the alphanumeric only.
You could create a function that eliminates the characters that do not interest you.
CREATE FUNCTION dbo.EliminaNoAlfanumericos(@variable varchar(100)) RETURNS VARCHAR(100)
BEGIN
DECLARE @posicion INT
SET @posicion = PATINDEX('%[^A-Za-z0-9]%',@variable )
WHILE @posicion > 0
BEGIN
SET @variable = STUFF(@variable ,@posicion ,1,'')
SET @posicion = PATINDEX('%[^A-Za-z0-9]%',@variable )
END
RETURN @variable
END
GO
The function what is doing is a loop looking, with PATINDEX
, the non-alphanumeric characters that contains the @variable
until none is left, and using the function STUFF
, is replacing by white ''
the character found in @posición
within @variable
.