-
Create column based on other columns
Hi,
I need to create a column with values based on other columns. I was thinking of creating a view that
selects from a table and creates a new column based on values in other columns. Example, i want to create
the column A with value 1 if there are existing values(no zeros or NULLs) in column B or if the column C has existing values
column A should have value 2. Column B and C can not have values at the same time.
-
--Computed columns (SQL Server)
create table A1(B int, A as Case when B is NULL or B =0 then 0 else 1 end)
go
insert into A1 (b) select NULL
insert into A1 (b) select 0
insert into A1 (b) select 100
select * from A1
--Result
B,A
NULL,0
0,0
100,1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|