MyBB Community Forums

Full Version: Mysql Conditionals or Triggers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have tried Mysql Conditionals or Triggers to do a insert
SELECT IF(((SELECT COUNT( * ) FROM `cpupreorden` WHERE `ordencompra` = '18066100554753d281877d15.06587328' GROUP BY `ordencompra` ) >0), '', INSERT INTO `cpupreorden` (`id`, 

`user`, `modelo`, `componente`, `ide`, `precio`, `ordencompra`, `fecha`) VALUES (1, 'Augustino', '1', 'Gabinete', 1, 55, '286183694753bd5b9935b4.09133438', '2007-12-03 

03:45:52'))

#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 'INTO cpupreorden (id,

user, modelo, componente, ide, precio, `' at line 1

CREATE TRIGGER 'inser' BEFORE INSERT ON `cpupreorden`;
BEGIN
DECLARE
	@numres int,
	FOR EACH ROW 
	BEGIN
		SELECT @numres = COUNT( * ) FROM `cpupreorden` WHERE `ordencompra` = '18066100554753d281877d15.06587328' GROUP BY `ordencompra`;
	IF @numres = '0'
		BEGIN
			INSERT INTO `cpupreorden` ( `id` , `user` , `modelo` , `componente` , `ide` , `precio` , `ordencompra` , `fecha` )
VALUES (
'', 'Augustino', '1', 'Gabinete', '1', '55', '18066100554753d281877d15.06587328', now( ));
		END;
 	END;
	END;

#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
@numres int,
MyBB Related?
LeX- Wrote:MyBB Related?
Yes, Of course
Augustino Wrote:
LeX- Wrote:MyBB Related?
Yes, Of course

We only give support for MyBB Issues - That code above is not in MyBB. So it looks like this thread was moved to Chit-Chat. As for the code I'm not very familiar with triggers