To solve this problem, you must use a computed column. Something with a definition like this:
A calculated column is calculated from an expression that can use other columns in the same table. An expression can be an incomplete column name, constant, function, and any combination of them, related one or more operators. An expression cannot be a subquery.
Unless otherwise specified, computed columns are virtual columns that are not physically stored in the table. Their values ββare recalculated every time they refer to the request. The Database Engine uses the PERSISTED keyword in the CREATE TABLE and ALTER TABLE statements to physically store computed columns in a table. Their values ββare updated when any columns that are part of their calculation change. From marking a computed column as PERSISTED, you can create an index on a computed column that is deterministic but not accurate. Additionally, if the computed column refers to a CLR function, the Database Engine cannot check if the function is actually deterministic. In this case, the computed column must be PERSISTED so that indexes can be created on it. For more information, see Creating Indexes on Computed Columns.
Computed columns can be used in selected lists, WHERE, ORDER BY clauses, or any other locations in which regular expressions may be followed by the following exceptions:
Computed columns used as CHECK, FOREIGN KEY, or NOT NULL constraints must be marked Stored. A calculated column can be used as a key column in an index or as part of any PRIMARY KEY or UNIQUE if the value of the calculated column is determined by a deterministic expression and the result data type is allowed in the index columns.
For example, if a table has integer columns a and b, the calculated column a + b may be indexed, but the calculated column a + DATEPART (dd, GETDATE ()) cannot be indexed, since the value may change> in subsequent calls.
The calculated column cannot be the object of an INSERT or UPDATE statement.
The database engine automatically determines the invalidity of calculated columns based on the expressions used. The result of most expressions is considered null, even if only immutable columns are present, because possible flows or overflows will be null results. Use the COLUMNPROPERTY function using the AllowsNull property that examines the nullability value of any computed column in the table. An expression that is null can be made immutable by specifying ISNULL (check_expression, constant), where the constant is a non-null value, replaced by any null result.