Question : SQL IF statement

I have the following code which generates an error:

The multi-part identifier "AE_Not_Frequent_attenders.age" could not be bound.

Here is the code. I am not sure how to fix it?

create procedure delete_rows
as
IF AE_Not_Frequent_attenders.age >16
      DELETE FROM AE_Not_Frequent_attenders WHERE AE_Not_Frequent_attenders.AttendanceTotal <=3

ELSE

IF AE_Not_Frequent_attenders.age <= 16
      DELETE FROM AE_Not_Frequent_attenders WHERE AE_Not_Frequent_attenders.AttendanceTotal <2


Answer : SQL IF statement

You cannot refernce the columns like that in a IF Statement.

You do something like the following:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
create procedure delete_rows 
as

DELETE 
   AE_Not_Frequent_attenders
FROM 
  AE_Not_Frequent_attenders 
WHERE 
(
          AE_Not_Frequent_attenders.AttendanceTotal <=3
          AND 
          AE_Not_Frequent_attenders.age >16
)
OR
(
         AE_Not_Frequent_attenders.age <= 16 
         AND
         AE_Not_Frequent_attenders.AttendanceTotal <2
)
Random Solutions  
 
programming4us programming4us