Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Article Discussion
 Find and Replace Partnumbers in string

Author  Topic 

minimotorsport
Starting Member

13 Posts

Posted - 2002-03-26 : 19:26:52
I have product database (webkatalog) with a string field (Detail) witch may contain one or more Partnumbers.
I want to put tags around them , if the Partnumber is also in the database.

I have tried some:

Replace(Detail,partnumber,"<B>" + partnumber +"</B>")

but can not find the right Select to find all partnumbers.



yours faithfully

Michael

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-03-26 : 20:26:21
Take a look at:
http://sqlteam.com/item.asp?ItemID=1876

That shows you how to find keywords in a varchar field in a table. You should be able to apply the same concepts to find the partnumbers in your field. If I'm reading correctly, I think what you wnt to do is put all the part numbers into a temp table that contains the RecordId and the partnumber. Each RecordID could have multiple part numbers associated with it. Once you have this table, you should be able to fairly easily update the "detail" field by selecting from this temp table.

Could you also post a few sample records of the "Detail" field? That would greatly help as well.

Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-03-26 : 21:00:07
Hi minimotorsport

From what you said, I think you've got a table like this:
PARTNUMBER DETAIL
----------------------
PART01 PART02, PART08, PART04
PART02 NULL
PART03 PART05
PART04 PART06, PART07, PART08
PART05 NULL

And you want

PARTNUMBER DETAIL
----------------------
PART01 <b>PART02</b>, PART08, <b>PART04</b>
PART02 NULL
PART03 <b>PART05</b>
PART04 PART06, PART07, PART08
PART05 NULL


Is that right?

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

minimotorsport
Starting Member

13 Posts

Posted - 2002-03-27 : 04:29:35
yes. Any idea ?


yours faithfully

Michael
Go to Top of Page

minimotorsport
Starting Member

13 Posts

Posted - 2002-03-27 : 05:28:17
quote:

Take a look at:
http://sqlteam.com/item.asp?ItemID=1876

That shows you how to find keywords in a varchar field in a table. You should be able to apply the same concepts to find the partnumbers in your field. If I'm reading correctly, I think what you wnt to do is put all the part numbers into a temp table that contains the RecordId and the partnumber. Each RecordID could have multiple part numbers associated with it. Once you have this table, you should be able to fairly easily update the "detail" field by selecting from this temp table.

Could you also post a few sample records of the "Detail" field? That would greatly help as well.





partnumber Detail
____________ ______________________________________________
1 like that in blue use 3 or 4
2 you better use 6
3 8 is cheaper
4 you can also use 1 for that
5
6 better than 2
7

and thats what I want to have:


partnumber Detail
____________ __________________________________________________
1 like that in blue use <B>3</B> or <B>4</B>
2 you better use <B>6</B>
3 8 is cheaper
4 you can also use <B>1</B> for that
5
6 better than <B>2</B>
7





yours faithfully

Michael
Go to Top of Page

minimotorsport
Starting Member

13 Posts

Posted - 2002-03-27 : 12:52:02
how can I do the following ?

for every [Artikelnummer] from webkatalog

do the following

Replace(Detail,[Artikelnummer],"<B>"+[Artikelnummer]+"</B>")
from webkatalog

something like that.




yours faithfully

Michael
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-04-01 : 19:52:58
Sorry, but I can't see any easy way. I think you're going to probably (dare I say it)
* cursor through each record
* loop through each ocurrence of partnumber in each string
* check for a match and insert
<b></b>
tags as required

Someone else may know a better method, but straight after the easter long-weekend - quite frankly I can't see it...

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -