Exporting HTML data from SQL to CSV

  • Hello, Is it possible to export HTML code to a CSV file and present the information has HTML?  I have attempted to do this using BCP but the export prints only the actual field values (HTML tags etc.)Here is what my BCP comment looks like followed by my table (code sample)[br]  declare @bcpcmd nvarchar(4000)
      SELECT @bcpcmd = 'bcp "SELECT * FROM ##HTML" queryout "c:\Temp\Test_' + replace(CONVERT(varchar,getDate(),112),'/',' ') + '.csv" -c  -T'
      EXEC master..xp_cmdshell @bcpcmd[br]CREATE TABLE ##HTML (RowID int identity(1,1), tags nvarchar(MAX))

    INSERT INTO ##HTML (Tags) VALUES ('<TABLE BORDER=1 CELLPADDING=2 CELLSPACING=2><TR><TD><TABLE WIDTH=100% BGCOLOR=#000000 CELLPADDING=2 CELLSPACING=2><TR><TD><font face=arial color=#FFFFFF><B>VP</B></TD></TR></TABLE><TABLE BORDER=1 height=400><TR>')
    INSERT INTO ##HTML (Tags) VALUES ('<TD><TABLE BORDER=1 WIDTH=100%><TR><TD BGCOLOR=#800000><font color=#FFFFFF face=arial><B>Test 1</B></TD></TR></TABLE><TABLE><TR><TD><font face=arial>A</TD></TR></TABLE><TABLE><TR><TD><font face=arial><BR>B<BR>C<BR>D<BR>E</TD></TR></TABLE><TABLE><TR><TD><font face=arial><BR>F<BR>G<BR>H<BR>I<BR>J</TD></TR></TABLE></TD>')
    INSERT INTO ##HTML (Tags) VALUES ('<TD><TABLE BORDER=1 WIDTH=100%><TR><TD BGCOLOR=#800000><font color=#FFFFFF face=arial><B>Test 2</B></TD></TR></TABLE><TABLE><TR><TD><font face=arial>A</TD></TR></TABLE><TABLE><TR><TD><font face=arial><BR>B<BR>C<BR>D<BR>E</TD></TR></TABLE><TABLE><TR><TD><font face=arial><BR>F<BR>G<BR>H<BR>I<BR>J</TD></TR></TABLE></TD>')
    INSERT INTO ##HTML (Tags) VALUES ('<TD><TABLE BORDER=1 WIDTH=100%><TR><TD BGCOLOR=#800000><font color=#FFFFFF face=arial><B>Test 3</B></TD></TR></TABLE><TABLE><TR><TD><font face=arial>A</TD></TR></TABLE><TABLE><TR><TD><font face=arial><BR>B<BR>C<BR>D<BR>E</TD></TR></TABLE><TABLE><TR><TD><font face=arial><BR>F<BR>G<BR>H<BR>I<BR>J</TD></TR></TABLE></TD>')
    INSERT INTO ##HTML (Tags) VALUES ('</TR></TABLE>')

    -- SELECT * FROM ##HTML
    -- DROP TABLE ##HTML

  • What do you mean by 'but the export prints only the actual field values'? What are you expecting it to do?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Phil Parkin - Friday, January 13, 2017 1:20 PM

    What do you mean by 'but the export prints only the actual field values'? What are you expecting it to do?

    Hi, Thank you for your reply.  What  I was thinking, and may be wrong, is that there is code in ASP that will convert HTML to an Excel file. 
    If you put the line "Response.ContentType = "application/vnd.ms-excel"" at the top of an HTML webpage, the file will convert the HTML to an Excel file. 

    I was thinking that there must be a way to do this in BCP or PROC somehow.

    I am trying to create a workaround for something because we do not have the correct reporting tools.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply