Hi i\'m trying to write If statement in Band Attribute but without Success T_T. what Im trying to do is have single Character A, B, C, D depending on the owner_category, Sheds a
Read the documentation on virtual columns:
CREATE TABLE Rent_Band
(
Plot_ID NUMBER(3),
Band VARCHAR(1) AS
(CASE WHEN Owner_Category = 'Council' AND Sheds ='No' THEN 'A'
WHEN Owner_Category = 'Private' AND Water_Supply ='Yes' THEN 'D'
WHEN Owner_Category = 'Council' AND Water_Supply ='No' AND Sheds ='Yes' THEN 'B'
WHEN Owner_Category = 'Private' AND Water_Supply ='No' AND Sheds ='No' THEN 'B'
ELSE 'C' END),
Rent_Charge NUMBER(4),
Owner_Category VARCHAR(10) CONSTRAINT Checking_Owner_Category CHECK((Owner_Category='Private') OR (Owner_Category='Council')),
Sheds VARCHAR(3) CHECK((Sheds='Yes') OR (Sheds='No')),
Water_Supply VARCHAR(3) CHECK((Water_Supply='Yes') OR (Water_Supply='No'))
)
BTW, I would STRONGLY recommend:
bit
field instead of a Yes
/No
constraint for Sheds
and Water_Supply
(saves room and overhead checking constraints, and translates directly to boolean in most app languages)Owner_Category
instead of a string constraint for basically the same reasons