LEFT(SUBSTRING_INDEX(LEFT(log, LOCATE('\n', log, LOCATE('tested this',
log)) - 1), '\n', -1), 8)
FROM test WHERE log LIKE '%tested this%'
Don't try this at home.
----- Original Message -----
From: "Ed Reed" <EReed@stripped>
Sent: Thursday, March 24, 2005 3:37 PM
Subject: Re: a very tricky string extraction
> Thanks Shawn,
> The idea I've been working with on this is to use an InStr to find the
> point where the require substring appears. Then I need to search
> backwards from there to the point where the first \n\r is found. Then
> the Date that I want would be 8 characters from that position. The
> obvious problem is that there doesn't seem to be an easy way to search
> backwards through a string.
> Any ideas on that line of thought?
> - Ed
>>>> <SGreen@stripped> 3/24/05 1:18 PM >>>
> "Ed Reed" < EReed@stripped > wrote on 03/24/2005 04:02:28 PM:
>> Sorry everyone for not being more clear. The field IS in a multiline
>> varchar field. The example data was all from one record in the
>> Unfortunately, this is a database that has been around for many
>> and backward compatibility with other apps limits redesigning the
>> It is a Comments field and this is the first time anyone has ever
>> to mine any data from it. My app is a generic report writer that
>> takes and query string and returns the results. No processing of the
>> data can be done in the app. I need the result to come directly from
>> Thanks again.
>> - Ed
>> >>> Keith Ivey < keith@stripped > 3/24/05 12:04 PM
>> Dan Nelson wrote:
>> > How about:
>> > SELECT LEFT(description, 8) FROM mytable WHERE description LIKE
>> "%tested this%" LIMIT 1
>> Hmm, I assumed he was talking about a multi-line VARCHAR, but
>> now that I look again Dan's interpretation is probably the right
>> one. My previous message doesn't apply (except for the bit
>> about breaking it into columns if you're doing it regularly).
>> Keith Ivey < keith@stripped >
>> Smokefree DC
>> Washington, DC
> Then I think you are stuck. What you are trying to find is a minimum
> value from a certain kind of row within a block of undelimited text.
> That's like hiding a whole table within a field and trying to write a
> query to find a field within the table within the field. Unless your
> happens to be extremely well formatted, you have no chance of doing an
> extract in pure SQL and I would say this is definitely not possible
> a single SQL statement.
> It may be possible in a single statement if you create a custom UDF
> parses through that "comments" field. Suppose you wrote the UDF to use
> this API
> FIND_IN_COMMENTS(<part you want>,<field to search>)
> Then you could program the UDF to find various <part>s like "first test
> date", "last test date", "first review date", "First review person",
> in any field that looks like your comments block. However, I believe
> this kind of text manipulation and searching is more complex than can
> easily achieved through just SQL and defintely too complex for a single
> Shawn Green
> Database Administrator
> Unimin Corporation - Spruce Pine