I am trying to extract data from a text string and as near as I can tell I have it except for problems with carriage returns.
examples of the data are as follows
DMSERVER-web 01/16/09 - Deal Completed and Finalized by Fred Beans GM DM-011609-46 b4- 490 pcs 86 lines $2068.02 Aft - 10 pcs 7 lines $252.41 <email address>
DMSERVER-web 1/16/2009 3:15:02 PM Sent To Seller Carfagno Chevrolet - DM-011609-46 / Steve Hartley / <phone#>, po- JAB375 aft - 10pcs 7 lines $252.41 Amt b4 - DM-011609-46/490 pcs 86 lines $252.41 Aft - 10 pcs 7 lines $252.41 <email address>
DMSERVER-web 01/16/09 - Deal Completed and Finalized by Evergreen Ford DM-011609-36 b4- 72 pcs 18 lines $720.41 Aft - 21 pcs 6 lines $681.14 <email address>
DMSERVER-web 1/16/2009 1:59:02 PM Sent To Seller Ultimate Ford - DM-011609-36 / Rebecca Guthrie / <phone#>, po- aft - 21pcs 6 lines $681.14 Amt b4 - DM-011609-36/72 pcs 18 lines $681.14 Aft - 21 pcs 6 lines $681.14 <email address>
DMSERVER-web 12/22/2008 11:37:57 AM Sent To Seller Southland Ford - DM-122208-10-69 / Chris Goodman / <phone#> aft - 4pcs 4 lines $275.56 Amt b4 - DM-122208-10-69/4 pcs 4 lines $275.56 Aft - 4 pcs 4 lines $275.56 <email address>
I am trying to extract the DM-######-## (the length varies but you get the idea)
I have started with a view with this select statement
SELECT SUBSTRING(NOTES, CHARINDEX('dm-', NOTES), 25)as bob
and it trims the results to this
DM-110909-56
b4
DM-110909-56 /
DM-110509-101
b
DM-110509-101
DM-110609-120
b
with a subsequent view of this
SELECT SUBSTRING(bob, CHARINDEX(CHAR(13), bob) + 1, CHARINDEX(' ', bob)) AS phil
FROM dbo.vw1stnotes
the results look like this
DM-011609-46
b4-
DM-011609-46
DM-011609-36
b4-
DM-011609-36
DM-122208-10-69
But so far any attempt the use substring with the end character being CHAR(13) to remove the "b4" values has failed. Does anyone have any suggestions or a different method than what I'm currently using that will get me the results I want?