1

I want to append everything in Field1 to Field2 and then make Field1 values NULL for all records in the table. I do not want to merge these fields into a single field, I still want both fields to remain.

Take the following example:

Field 1       Field 2
Test Value    NULL
NULL          Another Value
My Value      Current Value

I want to end up with:

Field 1       Field 2
NULL          Test Value
NULL          Another Value
NULL          Current ValueMyValue

Thanks in advance!

3 Answers 3

6

How about:

UPDATE table
SET Field2 = isnull(Field2,'') + isnull(Field1,''), Field1 = NULL

What I would suggest if you are not sure about it is to wrap the update in a BEGIN TRAN, ROLLBACK like so:

BEGIN TRAN

SELECT * FROM thistable

UPDATE thistable
SET Field2 = isnull(Field2,'') + isnull(Field1,'')
, Field1 = NULL

SELECT * FROM thistable

ROLLBACK

That way you will get a view of what the query will do before it makes the change 'permanent'. Once you are happy change ROLLBACK to COMMIT and run again.

VIEW DEMO HERE

Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfect! Thanks for the demo.
0

How about:

UPDATE MyTable
SET Field2 = ISNULL(Field2, '') + ISNULL(Field1, '')

To join the values into Field2.

And

UPDATE MyTable
SET Field1 = NULL

To clear out Field1 once you are sure the first script worked.

Comments

0

How about a little something like this:

UPDATE <Table name> SET field_2 = CONCAT(field_2, field_1);
UPDATE <Table name> SET field_1 = NULL;

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.