Hi,
I am hoping someone can help me here.
I am trying to take certin text out of one text field in a table. This one table holds account history.
By using Substring and Patindex i have been able to see what a customer has moved from and to and put these into two fileds in the select statement. however when i try and do the same to get the price of the product before and after i can not get it to work. I am getting errors:Invalid length parameter passed to the SUBSTRING function.. or no data back altogether.
I have created an example of what i am doing and any sugesstions would be greatly appriciated.
--Create and Insert:
CREATE TABLE Account_history(history_te
xt text not null);
insert into Account_history (history_text) values ('<b>Product</b> changed from <b>BOOK 1</b> to <b>BOOK 2</b><BR><b>Recurring Fee</b> changed from <b>6324.00</b> to <b>3255</b>')
--Statement:
select
SUBSTRING(history_text, 32, PATINDEX('%</b>%', SUBSTRING(history_text,32,
50))+0) AS MoveFrom_Product,--substri
ng passes all the text up to char 32,PATINDEX passes all the wildcards used
SUBSTRING(history_text,32+
PATINDEX('
%<b>%',SUB
STRING(his
tory_text,
32,50))+2,
PATINDEX('%</b>%',SUBSTRIN
G(history_
text,32+PA
TINDEX('%<
b>%',SUBST
RING(histo
ry_text,32
,50))+2,50
0))-1)AS MovedTo_product
FROM Account_history
WHERE history_text LIKE '<b>Product</b> changed from%to%'
AND history_text NOT LIKE '<b>Product</b> changed from <b></b> to <b>%'
Start Free Trial