I have a table car_rental of which I am trying to check each tuple for overlapping dates, and RAISE an EXCEPTION error if these values overlap with my check_date function. But no matter what I do, I keep getting a syntax error on the first line of my function. What am I doing wrong?
CREATE FUNCTION check_date(IN i_sdate DATE, IN i_edate DATE, IN i_plate varchar(10), OUT overlap)
SET @i_sdate = start_date(i_sdate);
SET @i_edate = end_date(i_edate);
SET @i_plate = plate(i_plate);
BEGIN
SET overlap = SELECT CASE WHEN (
(@i_sdate BETWEEN start_date AND end_date AND @i_plate = plate FROM car_rental)OR
(@i_edate BETWEEN start_date AND end_date AND AND @i_plate = plate FROM car_rental)OR
(start_date BETWEEN @i_sdate AND @i_edate AND AND @i_plate = plate )
THEN
RAISE EXCEPTION 'unavailable --> %', plate
USING HINT = 'Car is unavailable';
)
set @something = ...is the sign of TSQL (but without semicolon as I remember).