Aug. 13th, 2010

davidn: (skull)
UPDATE lcmr.content_relationship SET content_entity=
(
	SELECT TOP 1 ce_id
	FROM lcmr.content_w_xms_name newContent
	WHERE newContent.content_type=130
	AND newContent.xms_name='Badger Mushrooms'
	
)
WHERE id IN
	(
	SELECT lcmr.content_relationship.id
	FROM lcmr.content_w_xms_name newContent, lcmr.content_relationship
	INNER JOIN lcmr.property_value
	ON (lcmr.content_relationship.id=lcmr.property_value.id)
	WHERE property=13
	AND lcmr.property_value.content_instance NOT IN
		(
		SELECT pvForExisting.content_instance
		FROM lcmr.property_value pvForExisting,
		     lcmr.content_relationship crForExisting
		WHERE pvForExisting.id = crForExisting.id
		AND pvForExisting.property = 13
		AND crForExisting.content_entity IN
			(
			SELECT TOP 1 ce_id
			FROM lcmr.content_w_xms_name newContent
			WHERE newContent.content_type=130
			AND newContent.xms_name='Badger Mushrooms'
			)
		)
	AND (newContent.content_type=130
	AND newContent.xms_name='Badger Mushrooms')
	AND content_entity IN
		(
		SELECT TOP 1 ce_id
		FROM lcmr.content_w_xms_name oldContent
		WHERE (oldContent.content_type=130)
		AND oldContent.xms_name='Cow Exploding'
		)
	)
;
DELETE FROM lcmr.property_value
WHERE id IN
	(
	SELECT pv.id
	FROM lcmr.property_value pv, lcmr.content_relationship cr
	WHERE pv.id = cr.id
	AND property=13
	AND content_entity IN
		(
		SELECT TOP 1 ce_id
		FROM lcmr.content_w_xms_name oldContent
		WHERE (oldContent.content_type=130)
		AND oldContent.xms_name='Cow Exploding'
		)
	)
;

A masterpiece. (This is just one of them - it has to do all this about 32 times for different locations.)

Note the fair amounts of repetition - SQL is not my strong point, and this probably does things 100 times slower than they could be. It might be possible in about four lines, I don't know.

Expand Cut Tags

No cut tags

May 2020

S M T W T F S
     12
3456789
1011121314 15 16
171819 20 212223
24252627 28 2930
31      

Most Popular Tags

Style Credit

Page generated Jun. 24th, 2025 11:35 pm
Powered by Dreamwidth Studios