Hello! How can I create a calculated field in mssql server? For example, there are [field1] and [field2], which should be calculated, depending on if the value of the first field, for example, from ... to ..., then field2 will have one value, and if field1 = from ... to. .. then another.

  • We read relational DBMS, normal forms. I don’t remember which one of them says that it’s impossible to store columns in the table that can be calculated by other fields of the same table. The logic you need should be implemented in SQL queries or in view (if there are any in ms sql) - jmu

2 answers 2

Like that:

create table t ( f1 int, f2 as case when f1 between 1 and 10 then 'one' else 'two' end ) insert into t(f1) values(2),(12) select * from t 

    This is a reference question only. It is better to look for the answer on the books, you can start here: Calculated columns .

    And you can still answer the answer here in this question, if you want urgently: SQL Server Calculated Column .