SQLTeam.com | Weblogs | Forums

Create auto column in SQL Table


Dear expert

I have Table in SQL Server, i want to create auto column based on two column
Column A, Column B
in column A having Account no. of client which is not null
in column B having Branch Account no. which is may be null or not null
now i want to create 3rd column based on below condition
if column B having value take value from column B,
if column B is blank then take value from column A

please help


can you try this
select coulmna,
case when cloumnb is not null then columnb else columna end as newcolumn
from yourtable


ALTER TABLE table_name
ADD [column C] AS COALESCE([column B], [column A])

SELECT [column C], ...
FROM table_name