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 |
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 |
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.
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);