Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MySQL Question

MySQL Question

Scheduled Pinned Locked Moved Database
androidiosmobilemysqlsysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SQL Ed
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • S SQL Ed

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      SQL Ed wrote:

      I keep getting a syntax error

      On which line? I suggest you comment out blocks of sql, until you have a working version.

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups