Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 NOT TO SHOW HTML TAGS

Author  Topic 

tahseenm
Yak Posting Veteran

64 Posts

Posted - 2010-08-09 : 16:12:23
OUR VENDOR DATABASE IS IN SQL 2005 AND ONE OF THE COMMENTS FIELD STORING AS A HTML FORMAT AND IT SHOW AS HTML TAG AND THE OUTPUT PRINTOUT AS A SQL REPORT IS VERY HARD TO READ. CAN ANYONE SUGGEST HOW TO FIX THIS ONE TO NOT TO SHOW THE HTML TAGS THE OUTPUT SHOULD BE IN A READABLE FORMAT. HERE IS THE EXAMPLE BELOW HOW THE OUTPUT PRINTOUT LOOKS LIKE

EXAMPLE:

<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><FONT face="Times New Roman">Notify operation of work to be done <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">Lockout/Tag out <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Inspect water pump for leaks <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Check oil level and wicks on water pump <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Remove front cover and inspect /have operators clean out <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Lubricate linkage on boiler blower <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Check all boiler piping for leaks <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Clean and inspect flame traps and arrestors <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">Clean job site

moetahsen

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-09 : 22:24:42
They're creating the HTML documents in MS Word?! You're in for a long day

SQL output isn't meant to be in a readable format. The client should put it in a readable format.

Anyway, none of that helps you. If you really want to strip away the tags, start practicing with the REPLACE() and SUBSTRING() function.

Not going to be fun, but it can be done.

Might as well have a peek at this too: http://msdn.microsoft.com/en-us/library/ms181984.aspx
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-10 : 04:06:37
This is what we use:

--
PRINT 'Create function kk_FN_UTIL_RemoveHTML'
GO

IF 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_RemoveHTML
GO

CREATE 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)
*/
BEGIN
DECLARE @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
, '&lt;', '<')
, '&gt;', '>')
, '&nbsp;', ' ')
, '&amp;', '&') -- Last - to preserve nested ampersands

RETURN @strHTML

/** TEST RIG

SELECT '<xxx>Leading tag', dbo.kk_FN_UTIL_RemoveHTML('<xxx>Leading tag', NULL) UNION ALL
SELECT 'Trailing tag<xxx>', dbo.kk_FN_UTIL_RemoveHTML('Trailing tag<xxx>', NULL) UNION ALL
SELECT 'Embedded<xxx>tag', dbo.kk_FN_UTIL_RemoveHTML('Embedded<xxx>tag', NULL) UNION ALL
SELECT '&lt;', dbo.kk_FN_UTIL_RemoveHTML('&lt;', NULL) UNION ALL
SELECT '&gt;', dbo.kk_FN_UTIL_RemoveHTML('&gt;', NULL) UNION ALL
SELECT '&amp;', dbo.kk_FN_UTIL_RemoveHTML('&amp;', NULL) UNION ALL
SELECT '&amp;amp; nested', dbo.kk_FN_UTIL_RemoveHTML('&amp;amp; nested', NULL) UNION ALL
SELECT '&amp;lt; nested', dbo.kk_FN_UTIL_RemoveHTML('&amp;lt; nested', NULL) UNION ALL
SELECT '<BR>', ']' + dbo.kk_FN_UTIL_RemoveHTML('<BR>', NULL) + '[' UNION ALL
SELECT '<BR />', ']' + dbo.kk_FN_UTIL_RemoveHTML('<BR />', NULL) + '[' UNION ALL
SELECT 'LT < Only', dbo.kk_FN_UTIL_RemoveHTML('LT < Only', NULL) UNION ALL
SELECT 'GT > Only', dbo.kk_FN_UTIL_RemoveHTML('GT > Only', NULL) UNION ALL
SELECT 'Error1 A < B <TAG>', dbo.kk_FN_UTIL_RemoveHTML('Error1 A < B <TAG>', NULL) UNION ALL
SELECT 'OK2 <TAG> A > B', dbo.kk_FN_UTIL_RemoveHTML('OK2 <TAG> A > B', NULL) UNION ALL
SELECT 'NULL', dbo.kk_FN_UTIL_RemoveHTML(NULL, NULL)

**/
--==================== kk_FN_UTIL_RemoveHTML ====================--
END
GO
PRINT 'Create function kk_FN_UTIL_RemoveHTML DONE'
GO
--
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-10 : 04:11:00
SELECT dbo.kk_FN_UTIL_RemoveHTML('<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><FONT face="Times New Roman">Notify operation of work to be done <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">Lockout/Tag out <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Inspect water pump for leaks <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Check oil level and wicks on water pump <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Remove front cover and inspect /have operators clean out <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Lubricate linkage on boiler blower <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Check all boiler piping for leaks <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Clean and inspect flame traps and arrestors <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">Clean job site', NULL)

gives

" Notify operation of work to be done Lockout/Tag out Inspect water pump for leaks Check oil level and wicks on water pump Remove front cover and inspect /have operators clean out Lubricate linkage on boiler blower Check all boiler piping for leaks Clean and inspect flame traps and arrestors Clean job site"
Go to Top of Page
   

- Advertisement -