This is what we use:--PRINT 'Create function kk_FN_UTIL_RemoveHTML'GOIF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[kk_FN_UTIL_RemoveHTML]') AND xtype IN (N'FN', N'IF', N'TF')) DROP FUNCTION dbo.kk_FN_UTIL_RemoveHTMLGOCREATE FUNCTION dbo.kk_FN_UTIL_RemoveHTML( @strHTML varchar(MAX), -- HTML Data @intOptions smallint -- [Unused, reserved for future expansion, pass as NULL])RETURNS varchar(MAX)/* WITH ENCRYPTION */AS/* * kk_FN_UTIL_RemoveHTML Remove HTML Tags * SELECT dbo.kk_FN_UTIL_RemoveHTML(@MyTextString, NULL) * * See: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=148522 * * Returns: * * varchar(MAX) */BEGINDECLARE @intStart int, @intLength int -- Replace common HTML entities with plain-text equivalent PRE SELECT @strHTML = REPLACE(REPLACE( @strHTML , '<br>', CHAR(13) + CHAR(10)) , '<br />', CHAR(13) + CHAR(10)) -- This is NOT infalible! SELECT @intLength = 1 -- Force first iteration WHILE @intLength >= 1 BEGIN -- Remove <...> SELECT @intStart = CHARINDEX('<', @strHTML), @intLength = CHARINDEX('>', @strHTML) - NullIf(@intStart, 0) + 1 IF @intLength >= 1 BEGIN SELECT @strHTML = STUFF(@strHTML, @intStart, @intLength, '') END END -- Replace common HTML entities with plain-text equivalent POST SELECT @strHTML = REPLACE(REPLACE(REPLACE(REPLACE( @strHTML , '<', '<') , '>', '>') , ' ', ' ') , '&', '&') -- Last - to preserve nested ampersands RETURN @strHTML/** TEST RIGSELECT '<xxx>Leading tag', dbo.kk_FN_UTIL_RemoveHTML('<xxx>Leading tag', NULL) UNION ALLSELECT 'Trailing tag<xxx>', dbo.kk_FN_UTIL_RemoveHTML('Trailing tag<xxx>', NULL) UNION ALLSELECT 'Embedded<xxx>tag', dbo.kk_FN_UTIL_RemoveHTML('Embedded<xxx>tag', NULL) UNION ALLSELECT '<', dbo.kk_FN_UTIL_RemoveHTML('<', NULL) UNION ALLSELECT '>', dbo.kk_FN_UTIL_RemoveHTML('>', NULL) UNION ALLSELECT '&', dbo.kk_FN_UTIL_RemoveHTML('&', NULL) UNION ALLSELECT '&amp; nested', dbo.kk_FN_UTIL_RemoveHTML('&amp; nested', NULL) UNION ALLSELECT '&lt; nested', dbo.kk_FN_UTIL_RemoveHTML('&lt; nested', NULL) UNION ALLSELECT '<BR>', ']' + dbo.kk_FN_UTIL_RemoveHTML('<BR>', NULL) + '[' UNION ALLSELECT '<BR />', ']' + dbo.kk_FN_UTIL_RemoveHTML('<BR />', NULL) + '[' UNION ALLSELECT 'LT < Only', dbo.kk_FN_UTIL_RemoveHTML('LT < Only', NULL) UNION ALLSELECT 'GT > Only', dbo.kk_FN_UTIL_RemoveHTML('GT > Only', NULL) UNION ALLSELECT 'Error1 A < B <TAG>', dbo.kk_FN_UTIL_RemoveHTML('Error1 A < B <TAG>', NULL) UNION ALLSELECT 'OK2 <TAG> A > B', dbo.kk_FN_UTIL_RemoveHTML('OK2 <TAG> A > B', NULL) UNION ALLSELECT 'NULL', dbo.kk_FN_UTIL_RemoveHTML(NULL, NULL)**/--==================== kk_FN_UTIL_RemoveHTML ====================--ENDGOPRINT 'Create function kk_FN_UTIL_RemoveHTML DONE'GO--