I have 1 table named Temp1 and Columns are as below. In this table we have to make sure that salary of employee for any designation must be in between TopRange and Bottom Range. So I need to create a column combining 2 column Salary Top Range and Salary Bottom range
Emp ID (primary key) Emp Name Designation Salary Salary top range salary bottom range
Sample data:
Emp ID -123, Emp Name - ABC, Designation - Executive, Salary -10000, Salary top range - 15000, Salary bottom Range - 3000
I want to create a column Range
with a value of 3000-15000
. Is that possible in SQL Server?
Advertisement
Answer
You can add a computed column:
alter table t add column salary_range as ( concat(bottom, '-', top) );
This column will be calculated when you query it, so it will always be up-to-date.
Note that range
is a SQL keyword, so I renamed it to salary_range
. As a keyword, it is used in defining the window frame for a window function.