MySQL Forums
Forum List  »  Italian

Re: Stored procedure - variabile per creazione tabella
Posted by: Diego Radica
Date: November 13, 2018 05:44AM

Ciao Stefano
al momento sto seguendo la strada più veloce con la select insert.
Ho integrato quanto precedente scritto con la query di select e insert, ma ho un problema sul testo della where condition

BEGIN
-- declare variables
DECLARE name_table varchar(15);
DECLARE varM varchar(10);
DECLARE varFind varchar(10);

-- setting statement
SET @name_table=CONCAT(MONTHNAME(NOW() - INTERVAL 1 MONTH),YEAR(NOW()));

SET @varM = STR_TO_DATE(MONTHNAME(NOW() - INTERVAL 1 MONTH),'%M');

SET @varFind = CONCAT(YEAR(NOW()),'-',@varM);

SET @table = CONCAT('CREATE TABLE `',@name_table,'` (`TimeLog` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`Zona` varchar(22) NOT NULL,`Sensore` varchar(20) NOT NULL,`T` float NOT NULL,`U` float NOT NULL,KEY `TimeLog` (`TimeLog`) USING BTREE) ENGINE=InnoDB DEFAULT CHARSET=utf8;');

SET @tableIns = CONCAT('INSERT INTO `',@name_table,'`(TimeLog,Zona,Sensore,T,U) select TimeLog,Zona,Sensore,T,U FROM TemperatureLOG_TEST where TimeLog LIKE `',@varFind,'`;');



PREPARE stmt from @table;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

PREPARE stmt from @tableIns;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;


END


Messaggio di MySQL: #1054 - Colonna sconosciuta '2018-0000-10-00' in 'where clause'

Il formato della data è "2018-10-22 03:56:32", infatti io estraggo "2018-10", ma poi nella query non viene interpretata bene. Come posso risolvere questo problema?

Se la query la scrivo con la condizione where proprio con il valore "2018-10", ricevo questo errore:
Messaggio di MySQL: #1054 - Colonna sconosciuta '1018-10' in 'where clause'

Grazie ancora

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Stored procedure - variabile per creazione tabella
515
November 13, 2018 05:44AM


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.