我试图在不使用过程或函数的情况下在 MySQL 中运行以下代码。我不断收到语法错误。有没有人看到这段代码有什么问题。我是否能够在不使用过程或函数的情况下运行此代码。
DECLARE @Machine varchar(30);
SET @Machine = @MachineType;
IF @Machine = 'server'
THEN SELECT COUNT(*) AS 'Total Servers'
FROM agentcomputers AS A
WHERE A.groupid IN('521','637');
ELSEIF @Machine = 'bdr server'
THEN SELECT COUNT(*) AS 'Total BDR Servers'
FROM agentcomputers AS A
WHERE A.groupid =521;
ELSEIF @Machine = 'non-bdr server'
THEN SELECT COUNT(*) AS 'Total Non-BDR Servers'
FROM agentcomputers AS A
WHERE A.groupid =637;
ELSEIF @Machine = 'workstation'
THEN SELECT COUNT(*) AS 'Total Workstations'
FROM agentcomputers AS A
WHERE A.groupid =638;
ELSEIF @Machine = 'laptop'
THEN SELECT COUNT(*) AS 'Total Laptops'
FROM agentcomputers AS A
WHERE A.groupid =650;
ELSEIF @Machine = 'monitored computer'
THEN SELECT COUNT(*) AS 'Total Monitored Computers'
FROM agentcomputers AS A
WHERE A.groupid =1;
ELSEIF @Machine = 'new computer'
THEN SELECT COUNT(*) AS 'Total New Computers'
FROM agentcomputers AS A
WHERE A.groupid =648;
ELSEIF @Machine = 'managed service'
THEN SELECT COUNT(*) AS 'Total Managed Services'
FROM agentcomputers AS A
WHERE A.groupid =522;
ELSEIF @Machine = 'allmachines'
THEN SELECT COUNT(*) AS 'Total Machines'
FROM agentcomputers AS A
WHERE A.groupid IN('1','521','522','637','638','648','650');
/*
THESE IF STATEMENTS RETURN THE COUNTS FOR THE MOBIL DEVICES
*/
ELSEIF @Machine = 'phone'
THEN SELECT COUNT(*) AS 'Total Mobil Phones'
FROM mobiledevices AS M
INNER JOIN mobilemastergroups AS MM
ON MM.groupID = M.deviceType
WHERE M.deviceType=2;
ELSEIF @Machine = 'tablet'
THEN SELECT COUNT(*) AS 'Total Mobil Tablets'
FROM mobiledevices AS M
INNER JOIN mobilemastergroups AS MM
ON MM.groupID = M.deviceType
WHERE M.deviceType=3;
ELSEIF @Machine = 'ios'
THEN SELECT COUNT(*) AS 'Total Mobil iOS Devices'
FROM mobiledevices AS M
INNER JOIN mobilemastergroups AS MM
ON MM.groupID = M.deviceType
WHERE M.deviceType=4;
ELSEIF @Machine = 'android'
THEN SELECT COUNT(*) AS 'Total Mobil Android Devices'
FROM mobiledevices AS M
INNER JOIN mobilemastergroups AS MM
ON MM.groupID = M.deviceType
WHERE M.deviceType=5;
ELSEIF @Machine = 'allmobil'
THEN SELECT COUNT(*) AS 'Total Mobil Devices'
FROM mobiledevices AS M;
END IF;