MySQL Question
-
I am trying to run the following code in MySQL without using a procedure or function. I keep getting a syntax error. Does anyone see anything wrong with this code. Am I able to run this code without using a procedure or function. 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 I
-
I am trying to run the following code in MySQL without using a procedure or function. I keep getting a syntax error. Does anyone see anything wrong with this code. Am I able to run this code without using a procedure or function. 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 I