473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to replace part of a text field with text stored in another table

Hi All, just wondering someone out there could help me solve a little problem in my mysql database:

Table 1 Name: wp_wpsc_product_files

Fields: ID, Name, Description, Additional_Description



Table 2 Name: wp_wpsc_productmeta

Fields: ID, Product_ID, Meta_key, Meta_Value

The Product_ID in the second table – is the link to the ID field in the wp_wpsc_product_files table

The table wp_wpsc_productmeta where meta_key = SKU has the info I need in the meta_value field for each
Product in the wp_wpsc_product_files table

In the additional_description field (its a long text field type) there is a string of characters within a lot of other info – the string is: HDKLEPTO
The HDKLEPTO string is in the additional_description field for every product in the product_files table.
I need to replace this HDKLEPTO string with the products correct info from the productmeta table which has the correct info for each product
In the meta_value field where the meta_key=SKU

Pseudo-code::

Update wp_wpsc_product_files
Set additional_description
Replace within additional_description HDKLEPTO
with value from wp_wpsc_productmeta meta_value field
join wp_wpsc_product_files and
Wp_wpsc_productmeta using product_id and ID field
Find meta_value where meta_key = “SKU”

note: the additional_description field contains other strings of info that I don't want to loose...only want to replace that one string with the correct value for that particular product by find the value for that product in the productmeta table.

hope this makes sense :)
Jun 25 '10 #1
2 2662
improvcornartist
303 Expert 100+
Can you use the REPLACE() function? Example, REPLACE(additional_description, "HDKLEPTO", wp_wpsc_productmeta.meta_value).
Jun 25 '10 #2
Hi All,

This is what I ended up having to do:

I copied the table structure for wp_wpsc_product_files to a temp table and added an extra field for meta_value as I just could not use the replace command with two tables at same time....dont know if its possible or not but. I then did:

SELECT all fields from wp_wpsc_product_list.name, wp_wpsc_productmeta.meta_value

FROM ((wp_wpsc_product_list LEFT JOIN wp_wpsc_item_category_assoc ON wp_wpsc_product_list.id = wp_wpsc_item_category_assoc.product_id) LEFT JOIN wp_wpsc_productmeta ON wp_wpsc_product_list.id = wp_wpsc_productmeta.product_id)

WHERE wp_wpsc_productmeta.meta_key = "SKU"

Saved the results to a csv file (with phpmyadmin), then imported into my new temp table (which then had the new extra field meta_value)

Then I did:

UPDATE temptable
SET temptable = replace(temp_table, 'HDKLETO', meta_value)

Then renamed my orig table to backup, and renamed my temp table to wp_wpsc_products
Jun 25 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: MARK | last post by:
Hi, Can anyone help me with some vb code as i have little or no know of this programming language. I have a SQL server containing my datatbase and using an Access front end. I have two table:...
1
by: MemphiDoug | last post by:
In my email field, I want to query only the aol.com users. I have tried ="**", I have tried LIKE "**", I have tried just "aol.com" I can't figure out how to have it give me only the people that...
3
by: bitoulis | last post by:
Hi, is it possible to use the records of a table as the field names of another table? If yes, how is it done? Thanks in advance Laertes
4
by: sparks | last post by:
Well I have an old database that all the text fields are set to 25-50 don't know why but I needed to change them all to 250. Well I wrote some code to change the size of the fields in the tables...
4
by: BinuKJ | last post by:
I have a table which can have records almost repeated set of records except the difference of the a filed which is a flag. this flag can have either a value CSI or CCN . I want to count the no CCN...
8
by: factory fred | last post by:
Hi, I hope some one can help with this frustrating but probably simple issue. I have 2 mysql tables, one called 'country' the other called 'businessdetails'. On my page I have a form, people will...
4
by: paulcrowsnest | last post by:
Hi everyone This is probably really simple, but it has me stumped. I have a form which gets its data from a table called "Dentistry", this table is linked to another table called...
6
by: joawhzr | last post by:
Hello, my friends, I hope this is not an already asked (and resolved) question: Is it possible to find out which word or words in a text field (an address for example) are in another table? and...
15
by: Kasghost | last post by:
Rarely do I play with access so please keep it simple if possible. What I have are 2 tables. In table1 I have two fields, both are text. Field1 lists application names (Access, Excel, IE 7, ect)....
1
by: cathycros | last post by:
Hi, I'm trying to take data from varchar fields in one table and copy it to Nvarchar fields in another table. (Long story - now dealing with multiple languages, not enough space in row in current...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.