-- PlaceNameUpdate.sql
/*
2013-02-17 Tom Holden ve3meo
Combines up to the first three parts of the Standardized Place name
(the Normalized column) and places the concatenated result in the
Name column of PlaceTable for Places having non-empty Normalized
fields.

Requires temp xPlacePartsTable generated by PlaceParse.sql or equiv.
AND (fake) RMNOCASE collation.
*/
UPDATE PlaceTable
SET Name = (
		SELECT CASE 
				WHEN Comma2 > Comma1 
					THEN Place1 || ', ' || Place2 || ', ' || Place3
				WHEN Comma1 > 0
					THEN Place1 || ', ' || Place2
				ELSE Place1
				END AS Name
		FROM xPlacePartsTable
		WHERE PlaceTable.PlaceID = xPlacePartsTable.PlaceID
		)
WHERE PlaceID IN (
		SELECT PlaceID
		FROM xPlacePartsTable
		);
