Ads were blocked - no problem. But keep in mind that developing HeidiSQL, user support and hosting takes time and money. You may want to send a donation instead.

You have an Error in your sql Syntax

doubt's profile image doubt posted 5 months ago in General Permalink

I am trying to get all datetime columns of a table and use the column in a cursor to execute a query. I need help. Here is my code: DECLARE done INT DEFAULT 0; DECLARE sname varchar(200); DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; DECLARE Spaltencursor CURSOR FOR Select col.column_name from information_schema.columns col join information_schema.tables tab on tab.table_schema = col.table_schema and tab.table_name = col.table_name and tab.table_type = 'BASE TABLE' where tab.table_name ='myTable' and data_Type ='datetime' and col.table_schema = 'myDatabase'; OPEN Spaltencursor; REPEAT FETCH Spaltencursor INTO sname; IF NOT done THEN SET @spalte=sname; SET @sql:=CONCAT('Select id, ',@Spalte, ' from adr_Kunden where YEAR(',@spalte, ')< 1800'); PREPARE dynamic_statement FROM @sql; EXECUTE dynamic_statement; DEALLOCATE PREPARE dynamic_statement; End if UNTIL done END REPEAT; Close Spaltencursor;

Please login to leave a reply, or register at first.




Ads were blocked - no problem. But keep in mind that developing HeidiSQL, user support and hosting takes time and money. You may want to send a donation instead.