I'm facing a little problem to create the table name dynamically.
For example ,
This query (SELECT DATE_FORMAT(NOW(),'%Y%m'))
returns 201702
My motive is to check whether the table exist. If it doesn't exist , it will create it automatically. Now here's my problem.
messages_`,datereturn
It seems I'm getting error for even compiling. How do we pass parameter to create the table?
Really appreciate your help.
Full Code:
BEGIN
SET datereturn = (SELECT DATE_FORMAT(NOW(),'%Y%m'));
CREATE TABLE IF NOT EXISTS `messages_`,datereturn (
`mid` bigint(17) NOT NULL,
`uid` int(11) NOT NULL,
`csid` int(11) NOT NULL,
`content` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`content_type` tinyint(4) NOT NULL,
`datecreated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`datecreated1` bigint(13) DEFAULT NULL,
PRIMARY KEY (`mid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
END
EDIT: it's different than the answer proposed. I'm making the table dynamic with MySQL 5.6. The above suggested thread doesn't work for my version. So, I don't know why it's a possible of duplicate.