SET @AgentID=1373\; 

DELETE FROM dba USING 
databasealerts AS dba
JOIN \`plugins\` AS p ON p.PluginID=SUBSTRING_INDEX(dba.fieldname,':',1)
WHERE dba.AgentID=@AgentID AND NOT CONCAT_WS(':', p.PluginId, p.MD5)=SUBSTRING_INDEX(dba.FieldName,':',2)\;

SELECT CONCAT_WS(' \r\n',
CONCAT_WS(' ','Name:',NULLIF(p.Name,''),CONCAT('(ID ',p.PluginId, ')')),
CONCAT('Category: ',NULLIF(p.Category,'')),
CONCAT('Version: ',NULLIF(p.Version,'')),
CONCAT('Release Date: ',DATE(p.ReleaseDate)),
CONCAT('Author: ',NULLIF(p.Author,'')),
CONCAT('Description: ',NULLIF(p.Description,p.Name)),
CONCAT('Type: ',IF(p.RemoteAgent=1,'Remote Agent Plugin','Server Plugin')),
CONCAT('Filename: ',p.FileName),
CONCAT('Dependant On: ',NULLIF(p.DependantOn,'')),
CONCAT('Is Official: ',IF(p.Official=1,'Yes','No')),
CONCAT('Is Community: ',IF(p.Community=1,'Yes',NULL)),
CONCAT('Hidden: ',IF(p.Hidden=1,'Yes',NULL)),
CONCAT('Load: ',IF(p.DoNotLoad=1,'No',NULL))
) AS testvalue, 
CONCAT_WS(':', p.PluginId, p.MD5, p.Name, p.Author) AS identity, 
1 AS computerid, '0' AS noalerts, '00:00:00' AS uptimestart, '23:59:59' AS uptimeend 
FROM \`plugins\` AS p
WHERE p.\`Enable\`=1\;
