0

I need to update all the records in the Client table if address_1 is blank, but address_2 is not. In those cases I want to move address_2 into address_1. Here is my query so far:

UPDATE Client SET Address_1 = 'address1', address_2 = ''
WHERE client_id = 'client_id'

But instead of passing in client_id, I want to update every record.

6
  • Leave out the where criteria perhaps -- that will update the entire table? What exactly are you trying to do? Commented Mar 4, 2016 at 19:18
  • I am trying to update our table where address 1 is blank but address 2 is not and move the adress 2 to address 1 Commented Mar 4, 2016 at 19:20
  • 1
    Update Client Set Address_1 = address_2, address_2 = '' where Address_1 = '' and address_2 <> '' Commented Mar 4, 2016 at 19:21
  • I ended up extracting the data onto excel and writing the script there thanks Commented Mar 4, 2016 at 19:39
  • @Lashane . . . You should make your comment an answer. Commented Mar 4, 2016 at 19:54

1 Answer 1

1

The query you need is

UPDATE client SET address_1 = address_2, address_2 = ''
WHERE address_1 = '' AND address_2 != ''

In the WHERE, it finds all the problem rows, then it moves address_2 to address_1 and blanks out address_2

Note: Make sure you're not confusing empty string '' with NULL. In DB2, those are not the same. If your values are actually NULL, your query would need to be:

UPDATE client SET address_1 = address_2, address_2 = NULL
WHERE address_1 IS NULL AND address_2 IS NOT NULL
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.