-2

This is the lo-fi current version of the table

ID Custom column Value Value2
1 X
2 Y

Want to populate the custom column with either X or Y as such:

ID Custom column Value Value2
1 X X
2 Y Y
FanoFN
  • 6,815
  • 2
  • 13
  • 33

2 Answers2

0

You can simply concatenate the values as in the example below:

SELECT 
    Title, 
    FirstName, 
    MiddleName, 
    LastName,
    Title + ' ' + FirstName + ' ' + MiddleName + ' ' + LastName as MailingName
FROM Person.Person

Example taken from: https://www.mssqltips.com/sqlservertip/2985/concatenate-sql-server-columns-into-a-string-with-concat/

If you need it to be other type than a string you can always cast it to the proper type.

PeterD
  • 108
  • 7
0

As a select, you can use coalesce():

select t.*,
       coalesce(value, value2) as custom_column
from t;

As an update:

update t
    set custom_column = coalesce(value, value2);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786