Q:

SQL Server - export data using regular expression?

I have a table I'm trying to export out of a SQL Server database. One of the columns is giving me a hard time and the Import and Export Wizard is throwing all kinds of errors. As soon as you remove this column, the export runs flawlessly.
The column in the database is storing a full HTML document as a text data type. I want to export just the text out of each field from this column between the DIV tags without the HTML.
For example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
    <STYLE type=text/css> P, UL, OL, DL, DIR, MENU, PRE { margin: 0 auto;}</STYLE>
    <META content="MSHTML 6.00.2900.3429" name=GENERATOR>
</HEAD>
<BODY leftMargin=1 topMargin=1 rightMargin=1>
    <FONT face=Tahoma size=2>
        <DIV>[REDACTED TEXT THAT I WANT TO EXPORT]</DIV>
    </FONT>
</BODY>
</HTML>

That is copy pasted out of one of the records. Every row has the same HTML in the record but I just want to export the redacted text.
Putting aside that the guy who designed this database/application was a moron, how do I grab that data? I'd even settle for pulling the full record with HTML if I could get the export wizard to work.
Edit: Here is the Import and Export Wizard report errors:

Operation stopped...
  - Initializing Data Flow Task (Success)
  - Initializing Connections (Success)
  - Setting SQL Command (Success)
  - Setting Source Connection (Success)
  - Setting Destination Connection (Success)
  - Validating (Success)
  - Prepare for Execute (Success)
  - Pre-execute (Success)
  - Executing (Warning)
  Messages
  * Warning: Preparation SQL Task 1: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. (SQL Server Import and Export Wizard)
  * Warning: Preparation SQL Task 1: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No
  work was done. (SQL Server Import and Export Wizard)

Copying to Query (Error)
  Messages  
Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x00040EDA.  
Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "input "Destination Input" (45)" failed because error code 0xC020907B occurred, and the error row
  disposition on "input "Destination Input" (45)" specifies failure on
  error. An error occurred on the specified object of the specified
  component.  There may be error messages posted before this with more
  information about the failure.  
Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component
  "Destination - Query" (34) failed with error code 0xC0209029 while
  processing input "Destination Input" (45). The identified component
  returned an error from the ProcessInput method. The error is specific
  to the component, but the error is fatal and will cause the Data Flow
  task to stop running.  There may be error messages posted before this
  with more information about the failure.
Error 0xc02020c4: Data Flow Task 1: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.
Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "Source  
Query" (1) returned error code 0xC02020C4.  The component returned a failure code when the pipeline engine called PrimeOutput(). The
  meaning of the failure code is defined by the component, but the error
  is fatal and the pipeline stopped executing.  There may be error
  messages posted before this with more information about the failure.
Post-execute (Success)
  Messages  
Information 0x4004300b: Data Flow Task 1: "component "Destination - Query" (34)" wrote 7465 rows.

A:

In your select statement for that field, extract only the part that you want using SUBSTRING and CHARINDEX to cut out the parts between the  tags, assuming you really only have one such tag per field.  Below, [HTML] is actually a cast of your field into a VARCHAR, so where you see [HTML] you'll put this:
CAST([YourHTMLFieldName] AS VARCHAR(MAX))

And this essentially says "give me the text between  and :
SELECT SUBSTRING([HTML], CHARINDEX('<DIV>', [HTML]), CHARINDEX([HTML], '</DIV>') - CHARINDEX([HTML], '<DIV>'))

You'll probably need to play with it a bit, like if the output erroneously includes the "" tag you can change it to "CHARINDEX('') + 5".

