2

I am using QGIS and want a query that will change a text value "TIPPERARY SOUTH" AND "TIPPERARY NORTH" to "TIPPERARY". Both TIPPERARY NORTH and TIPPERARY SOUTH are contained within a field called COUNTY. Is it possible for me to only update these entries within the COUNTY field, or do I need to create another field to do this. There are over 400 entries with both these names so it would take to long to do manually.

I have created the COUNTYNAME field if this is required but I would also need a query to Transfer across other values from the COUNTY field. This would be a like for like for the other entries e.g. I want value "DUBLIN" in "COUNTY" field to display as "DUBLIN" in the "COUNTYNAME" field.

enter image description here

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 5 at 22:09
2
  • 1
    The current answers below would also change "TIPPERARY WEST" to "TIPPERARY". As long as NORTH and SOUTH are the only TIPPERARYs (sorry, I don't know the place, its a long way...) then they'll do the job. Commented May 6 at 8:58
  • Thank you very much for the help! Commented May 6 at 19:26

2 Answers 2

3

We can update the existing field where the original values are stored but I suggest you update a separate field as not to risk loss of data.

We can update via the Field Calculator:
rc Layer > Layer Properties > Fields > Field Calculator.

In your case we can apply the following in the field calculator expression for the layer:

CASE
WHEN "COUNTY" LIKE 'TIPP%' THEN 'TIPPERARY'
ELSE "COUNTY"
END 

This will look for all text in the "COUNTY" field that start with 'TIPP' and set the new value to 'TIPPERARY'. For all other cases it will copy the original COUNTY value across, e.g. 'DUBLIN' will copy across as 'DUBLIN'.

Field Calculator Screenshot

answered May 6 at 0:10
1
  • Thank you so much for the quick reply, this query was perfect! Commented May 6 at 19:26
2

Update the field or create a new field with Field calculator using this expression:

regexp_replace ("COUNTY", 'TIPPERARY.*', 'TIPPERARY')

It uses Regular Expressions with function regexp_replace() to search for content in field COUNTY containing the text TIPPERARY and replaces (removes) all characters after this textstring, using .* (dot for any character and quantifier * for 0 or more of these).

Fields that do not contain TIPPERARY remain unchanged.

answered May 6 at 6:44
2
  • Thank you very much for this! Commented May 6 at 20:51
  • 1
    You're welcome. As a new user, please be adviced that this site tries to avoid "thank you" messages. Instead, it encourages you to accept the answer and/or upvote it: click the checkmark right to the answer to accept it - see: gis.stackexchange.com/help/someone-answers Just click the checkmark, see here: meta.stackexchange.com/questions/5234/… Commented May 6 at 22:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.