0

プロシージャまたは関数を使用せずに、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;
4

0 に答える 0