• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

SQL query to transfer info between fields?

fredrikse

Active member
#1
Hi,

I'm in need of a query that can transfer information between imported vB custom fields and newly created XenForo custom fields. The information is text or numeric values.
 

Jake Bunce

XenForo moderator
Staff member
#2
Code:
INSERT INTO xf_user_field_value (user_id, field_id, field_value)
	SELECT user_id, 'new_field_id', field_value
	FROM xf_user_field_value
	WHERE field_id = 'old_field_id'
ON DUPLICATE KEY UPDATE
	field_value = VALUES(field_value);
Then rebuild the user cache:

Admin CP -> Tools -> Rebuild Caches -> Rebuild User Caches
 

fredrikse

Active member
#3
Code:
INSERT INTO xf_user_field_value (user_id, field_id, field_value)
SELECT user_id, 'new_field_id', field_value
FROM xf_user_field_value
WHERE field_id = 'old_field_id'
ON DUPLICATE KEY UPDATE
field_value = VALUES(field_value);
Then rebuild the user cache:

Admin CP -> Tools -> Rebuild Caches -> Rebuild User Caches
This is great. Since I used swedish words for the field names in vBulletin I'm going to create new ones with english field IDs and transfer all information correspondingly.

What would the query look like if I want to transfer information from a custom field to, let's say for instance, the "about" field in XenForo?
 

Jake Bunce

XenForo moderator
Staff member
#4
What would the query look like if I want to transfer information from a custom field to, let's say for instance, the "about" field in XenForo?
Code:
UPDATE xf_user_profile AS up
SET up.about = (
	SELECT ufv.field_value
	FROM xf_user_field_value AS ufv
	WHERE ufv.user_id = up.user_id
	AND ufv.field_id = 'old_field_id'
);