SQLTeam.com | Weblogs | Forums

Create auto column in SQL Table


#1

Dear expert

I have Table in SQL Server, i want to create auto column based on two column
e.g.
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


#2

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


#3

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

SELECT [column C], ...
FROM table_name