Question : Set Trigger for Birthdate

I am trying to setup a trigger in SQL.  I know I have some errors below.  My table is tblRegistration.   I am trying to setup a trigger that will turn Combo1's value into a "3"  when the Birthdate of a student is over 18 years of age.

The data in Birthdate column is obviously their birthdate.  How can I set this trigger up properly.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
create trigger overage on tblRegistration
after insert, update
as
begin
update tblRegistration
set Combo1 = 3
from tblRegistration
where BirthDate " "
end

Answer : Set Trigger for Birthdate

instead of trigger you better define combo1 column as a computed column. the reason is when you insert you can test the age and accordingly set the combo1 value to 3 if age is >18. in cases like when data is inserted age is <=18years, combo1 value is set to <>3 when the person reaches 18years age you need to find the record and update it again. if you use computed column you will get the correct combo1 value depending on the age.

try computed column like this,

alter table tblRegistration  add new_Combo1 as case when BirthDate  < dateadd(yy, -18, getdate())  then 3 else 0 end
Random Solutions  
 
programming4us programming4us