syntax error for simple IF - THEN
-
Hi, I am trying to creat a simple IF - THEN in MySQL but getting a synax error message. can anyone help please... here is my statement:
IF EXISTS (SELECT payroll_id FROM payroll WHERE location_id = param_location AND payroll_month = param_month AND payroll_year = param_year) THEN
SET param_payroll_id = 0;
END IF;Technology News @ www.JassimRahma.com
-
Hi, I am trying to creat a simple IF - THEN in MySQL but getting a synax error message. can anyone help please... here is my statement:
IF EXISTS (SELECT payroll_id FROM payroll WHERE location_id = param_location AND payroll_month = param_month AND payroll_year = param_year) THEN
SET param_payroll_id = 0;
END IF;Technology News @ www.JassimRahma.com
Never used MySql but based on my search, you can't use that syntax in Mysql. Alternate way is, just store the result of query into some variable & use it for comparison to achieve the output. Check this sample MySQL Stored Procedures IF NOT EXISTS()[^] BTW, always include the complete error message(just 'Syntax error' is not enough) in your question which is better for members to give you answers quickly.
thatraja
Coming soon1 | Coming soon2 | Coming soon3New
-
Never used MySql but based on my search, you can't use that syntax in Mysql. Alternate way is, just store the result of query into some variable & use it for comparison to achieve the output. Check this sample MySQL Stored Procedures IF NOT EXISTS()[^] BTW, always include the complete error message(just 'Syntax error' is not enough) in your question which is better for members to give you answers quickly.
thatraja
Coming soon1 | Coming soon2 | Coming soon3New
I tried below code but getting same error for the IF--THEN
SET param_payroll_exists = (SELECT COUNT(*) FROM payroll WHERE location_id = param_location AND payroll_month = param_month AND payroll_year = param_year);
IF EXISTS (param_payroll_exists > 0) THEN
SET param_payroll_id = 0;
END IF;the exact error is: You have an error in your SQL syntax. Check the manual that corresponds to you MySQL server for the right syntax to use near 'param_payroll_exists > 0) THEN ..........
Technology News @ www.JassimRahma.com
-
I tried below code but getting same error for the IF--THEN
SET param_payroll_exists = (SELECT COUNT(*) FROM payroll WHERE location_id = param_location AND payroll_month = param_month AND payroll_year = param_year);
IF EXISTS (param_payroll_exists > 0) THEN
SET param_payroll_id = 0;
END IF;the exact error is: You have an error in your SQL syntax. Check the manual that corresponds to you MySQL server for the right syntax to use near 'param_payroll_exists > 0) THEN ..........
Technology News @ www.JassimRahma.com
Jassim Rahma wrote:
IF EXISTS (param_payroll_exists > 0) THEN
Do you really mean EXISTS here?
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
I tried below code but getting same error for the IF--THEN
SET param_payroll_exists = (SELECT COUNT(*) FROM payroll WHERE location_id = param_location AND payroll_month = param_month AND payroll_year = param_year);
IF EXISTS (param_payroll_exists > 0) THEN
SET param_payroll_id = 0;
END IF;the exact error is: You have an error in your SQL syntax. Check the manual that corresponds to you MySQL server for the right syntax to use near 'param_payroll_exists > 0) THEN ..........
Technology News @ www.JassimRahma.com
You didn't get Peter's reply which's fair enough? Just remove
EXISTS
from that query & run. It's over.thatraja
Coming soon1 | Coming soon2 | Coming soon3New