This is the error i am getting and can't find where i am going wrong
any help would be highly appreciated
thanks,
SQL query:
CREATE PROCEDURE yearly_income_tax_calculation_federal( ) BEGIN DECLARE salary FLOAT;
MySQL said:
#1064 - 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 '' at line 5
procedure:
create procedure yearly_income_tax_calculation_federal()
begin
declare salary float;
declare tax float;
SELECT salary_annually INTO salary FROM ndcga776_payroll_db.payroll WHERE payroll_id=2;
IF (salary>0 AND salary<=44701) THEN SET tax = salary*0.15;
ELSE IF (salary>44701 and salary<=89401) THEN SET tax=44701*0.15+(salary-44701)*0.22;
ELSE IF (salary>89401 and salary<=138586) THEN SET tax=44701*0.15+(89401-44701)*0.22+(salary-89401)*0.26;
END IF
END IF
ELSE SET tax=44701*0.15+(89401-44701)*0.22+(138596-89401)*0.26+(salary-138586)*0.29;
END IF
end
Related
I tried to create this simple function, but I have the following error message;
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(customerLevel);
END' at line 17
here is the code:
DELIMITER $$
CREATE FUNCTION GetCustomerLevel(CustomerID INT)
RETURNS VARCHAR(20)
DETERMINISTIC
BEGIN
DECLARE credit DECIMAL(10,2) DEFAULT 0;
DECLARE customerLevel VARCHAR(20);
SELECT SUM(total_price)
INTO credit
FROM sales s,customer c
WHERE c.customer_id= CustomerID And s.customer_id=c.customer_id ;
IF credit > 1400 THEN
SET customerLevel = 'PLATINUM';
ELSE
SET customerLevel = 'NOT PLATINUM';
END IF;
RETURN (customerLevel);
END$$
DELIMITER ;
I just shut down MySQL server and restart it and the code run without any error!
Thanks all :)
I am using MySQL v5.0.92 and I'm trying to import some data, but I get an error on declare my variables.
BEGIN
DECLARE flag INT;
DECLARE id INT;
while flag=0 begin
SET id=(SELECT top 1 user_id
FROM ac_user_info WHERE user_id>#id order by user_id)
INSERT INTO cuddleew_database1.cewp_usermeta(user_id,meta_key,meta_value)
SELECT id,'first_name',first_name
FROM cuddleew_backup.ac_user_info WHERE user_id=#id
INSERT INTO cuddleew_database1.cewp_usermeta(user_id,meta_key,meta_value)
SELECT id,'last_name',last_name
FROM cuddleew_backup.ac_user_info WHERE user_id=#id
SET flag=(select case #id when(SELECT MAX(user_id)
FROM cuddleew_bakup.ac_user_info) then 1
else 0
END CASE)
END WHILE
END
In MySQL console i get this:
BEGIN DECLARE flag INT;
#1064 - 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 flag INT' at line 2.
Can you help me with this and tell me what's wrong. Thanks in advance.
You have to change your delimiter first, so the ; doesn't tell MySQL that this command is over.
DELIMITER $$
[your code here]
END $$
DELIMITER ;
I'm trying to set up a MySQL function for my Mail-server. The MySQL Version is 5.1.66.
I do know what is wrong with this query. I also tried with RETURN DOUBLE, READS SQL DATA, and DETERMINISTIC but none of them help.
I am using PhpMyAdmin. The delimiter is set to $$. But all I get is a cryptic error message:
#1064 - 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 'TEXT CHARSET utf8 READS SQL DATA BEGIN DECLARE mygoto VARCHAR(25' at line 3
My code:
CREATE PROCEDURE `get_email_alias`(
myemail VARCHAR(255)
) RETURNS TEXT CHARSET utf8
READS SQL DATA
BEGIN
DECLARE mygoto VARCHAR(255);
DECLARE sdomain VARCHAR(255);
DECLARE ddomain VARCHAR(255);
SELECT SUBSTRING(myemail, INSTR(myemail, '#')+1) INTO sdomain;
SELECT target_domain
FROM alias_domain
WHERE alias_domain = sdomain
AND active = 1
LIMIT 1
INTO ddomain;
IF ddomain IS NOT NULL THEN
SELECT REPLACE(myemail, sdomain, ddomain) INTO myemail;
END IF;
SELECT goto
FROM alias
WHERE address = myemail
AND active = 1
LIMIT 1
INTO mygoto;
IF mygoto IS NOT NULL THEN
RETURN mygoto;
END IF;
RETURN null;
END $$
For anyone that comes across this later:
There was originally a syntax error in the keyword PROCEDURE. It was missing the final E.
According to the MySQL syntax, CREATE PROCEDURE does not RETURN. However, CREATE FUNCTION does allow the RETURN in the syntax. Reference: http://dev.mysql.com/doc/refman/5.1/en/create-procedure.html.
PROCEDURE" on first line is missing "E"
I have this piece of code:
BEGIN
DECLARE #NewLine CHAR(2)
SET #NewLine = CHAR(13)+CHAR(10)
END
When I run it in phpmyadmin, I get this error:
#1064 - 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 #NewLine CHAR(2) SET #NewLine = CHAR(13) + CHAR(10) END' at line 2
I used about 2 hours on Google, without any luck. As far as I can tell, it should be the right syntax.
Someone please help
Flow statements like IF, WHEN and so on are only allowed in stored procedures or function in MySQL. BEGIN and END are delimiters of such statements.
Put that code in a procedure and it should work.
Edit
Example procedure
DELIMITER //
CREATE PROCEDURE newline_proc(input varchar(1000))
BEGIN
declare newline char(2);
select CHAR(13)+CHAR(10) into newline;
...
END//
DELIMITER ;
I want to execute the following code in MySql but I am getting the error
CREATE TRIGGER CINEMAHALLNO_GENERATE_TRIGGER
BEFORE INSERT ON CINEMA_HALLS
FOR EACH ROW
BEGIN
DECLARE cnt DOUBLE;
DECLARE next1 DOUBLE;
SELECT COUNT(HALLNO) INTO cnt from CINEMA_HALLS;
IF cnt > 0 AND cnt < 20 THEN
SELECT MAX(HALLNO) INTO NEXT1 FROM CINEMA_HALLS;
set next1=next1+1;
SET :new.HALLNO=next;
ELSEIF cnt = 0 THEN
SET :new.HALLNO=1;
end if;
end;
Output Error:
SQL query:
CREATE TRIGGER CINEMAHALLNO_GENERATE_TRIGGER
BEFORE INSERT ON CINEMA_HALLS
FOR EACH ROW
BEGIN
DECLARE cnt DOUBLE
MySQL said: Documentation
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 5
Declare must be placed after the Begin.
Please check the following link