Steve Jones - SSC Editor (8/1/2011)
The default isn't an expression run against the row. It's a value. Same for computed columns, these don't allow logical expressions.A trigger is the best way to handle this.
Steve,
Actually logical expressions can be used for computed columns:
CREATE TABLE tblMine
( RecIDINT
, ApptType INT
, SevType AS CASE WHEN ApptType = 1 THEN 0
WHEN ApptType = 2 THEN 3
ELSE NULL END
)
INSERT INTO tblMine
( RecID, ApptType )
VALUES
( 1, 1 ),
( 2, 2 ),
( 3, 3),
( 4, NULL)
SELECT * FROM tblMine
Of course you can't update the computed column so it's kind of useless here.
I agree a trigger would be the way to go.
Todd Fifield