DECLARE @TYPE AS VARCHAR(1)
SET @TYPE = (SELECT phones.type FROM phones WHERE phones.phone_number = [Number])
IF @TYPE = '1'
BEGIN
SELECT phones.phone_number as PhoneMobile, phones.phone_number as EntityID, clients.id as contactid, first_name as firstname, last_name as lastname
FROM clients INNER JOIN phones ON clients.id = phones.type_id
WHERE (((phones.is_deleted)=0) AND ((phones.type)=1)
AND ((phones.phone_number) LIKE '%[Number]%')) END;
ELSE
BEGIN
SELECT phones.phone_number as PhoneMobile, phones.phone_number as EntityID, prospects.id as contactid, first_name as firstname, last_name as lastname
FROM prospects INNER JOIN phones ON prospects.id = phones.type_id
WHERE (((phones.is_deleted)=0) AND ((phones.type)=2)
AND ((phones.phone_number) LIKE '%[Number]%'))END;
END IF
END
Above is the SQL Statement. Below is the error I keep receiving:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @TYPE AS VARCHAR(1) SET @TYPE = (SELECT phones.type FROM phones WHERE p' at line 1
Can somebody let me know what i'm doing wrong? I'm not the best at MySQL. Looking for some insight. If possible can someone rewrite this in a way I can actually execute it?