MySQL Forums
Forum List  »  Triggers

row as variable in trigger
Posted by: Othmar Gattringer
Date: December 30, 2011 07:49AM

is it possible to use a variable into a insert statment for row selection.
---------------
DELIMITER $$

USE `wetter`$$

DROP TRIGGER /*!50032 IF EXISTS */ `trigger_test`$$

CREATE

TRIGGER `trigger_test` AFTER UPDATE ON `maintable`
FOR EACH ROW BEGIN
DECLARE wr_row VARCHAR(5);
SET wr_row = (SELECT CONCAT('wr_',ABS(CEIL((wind_richt-11.24)/22.5))) FROM maintable WHERE id=NEW.id);
INSERT INTO stundenmittelwert (id,counter,temp,hum,baro,wind,gust,regen,rainrate,sun,uv, wr_row )
SELECT maintable.id,1 ,maintable.temp,maintable.hum,1

FROM maintable WHERE id=NEW.id;
END;
$$

DELIMITER ;
-------------
if maintable wasupdated the trigger have to update the table stundenmittelwert
this contains row wr_0 to wr_15
The direction (windricht) will be calculated into 16 sectores. This sector will be set to 1 (wr_0=1 ...or wr_15=1)
So the row name is betwen wr_0 and wr_15. Values cant be assigned by a variable but row declaration possible?
I get always an error
Thanks Othmar

Options: ReplyQuote


Subject
Views
Written By
Posted
row as variable in trigger
2239
December 30, 2011 07:49AM
1027
January 17, 2012 09:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.