Jump to content


Check out our Community Blogs





- - - - -

Remove Characters in String T-SQL with No Loop Part 2

  Posted by Barnsite, 09 May 2016 · 9483 views

Okay, expanding on what I did yesterday.

I Built a table, called ExclusionList with one field, ExcludedText

E.g.

Untitled2

Then created a function:

CREATE FUNCTION [dbo].[udf_clean_string]
	(
	@string VARCHAR(100)
	) RETURNS VARCHAR(100)
AS
BEGIN	

SELECT
    @string = REPLACE(@string,ExcludedText,'')
FROM ExclusionList

RETURN @string

You can then use like this:

SELECT
	dbo.udf_clean_string(FieldName)
FROM TableName



Source

  • 0