mercredi 3 février 2016

if else in trigger in sql

I m trying to create after insert trigger with if else statement.I can do it without if else, but get error with it. So, in table 'booking' there is a column customer_id. There is a table customer, where i have a column 'type'. Depending on the value in this column i want add a row to booking_status table, but i get error in syntax. I m just learning sql, please, help if you can.

AFTER INSERT ON booking
FOR EACH ROW 
IF (SELECT type FROM customer WHERE ID=customer_id) = 'not trust'
BEGIN
INSERT INTO booking_status (id, status_name, booking_id) VALUES(NEW.booking_number, 'Checking', NEW.booking_number)
END
ELSE
INSERT INTO booking_status (id, status_name, booking_id) VALUES(NEW.booking_number, 'Approved', NEW.booking_number);

Aucun commentaire:

Enregistrer un commentaire