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 code- Problems with cade when inside a WHERE clause

MySQL code- Problems with cade when inside a WHERE clause

Scheduled Pinned Locked Moved Database
mysqlsysadminhelpquestion
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

    The following code keeps erroring out in MySQL Workbench. I have not been able to locate the syntax problem. Can anyone see whats wrong with this code. Runnining the code a section at a time still dosn't work. It errors at the first ; where I placed the MAD face. Cannot completely remove the errors they just keep changing places. Also is there a good library of code snippets to view if needed? /* PATCH MANAGEMENT */ DELIMITER $$ #MachineType means Server or Workstation as determined by the word server in the os field DROP PROCEDURE IF EXISTS usp_cbi_PatchManagement$$ CREATE PROCEDURE usp_cbi_PatchManagement(MasterGrp varchar(30),Criteria varchar(30),LocationID varchar(30), ClientName varchar(30)) BEGIN SELECT IFNULL(COUNT(DISTINCT A.computerid),0) AS 'Dynamic Machine Counts' FROM (SELECT HF.computerid, HF.hotfixID FROM hotfixdata HFD INNER JOIN hotfix HF ON HF.hotfixid = HFD.hotfixid AND HFD.ignore <> 1 LEFT OUTER JOIN Computers AS C ON C.ComputerID=HF.ComputerID LEFT OUTER JOIN locations AS L ON C.LocationID=L.LocationID LEFT OUTER JOIN Clients AS CL ON C.ClientID=CL.ClientID JOIN agentcomputers AS AC ON C.ComputerID=AC.computerid JOIN mastergroups AS MG ON AC.groupid=MG.groupId #Enter Case When here seperating different where clauses. WHERE CASE WHEN Criteria = 'Workstations Missing Patches' THEN INSTR(C.os,"server")=0 AND INSTR(C.os,"microsoft")>0 AND HF.installed <> 1 AND HF.Approved = 1 AND LocationID = L.Name AND ClientName = Cl.Name :mad: AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Workstations with Empty Patch Tabs' THEN HF.hotfixid IS NULL AND (C.lastcontact > DATE_ADD(NOW(),INTERVAL -7 DAY)) AND INSTR(C.OS,"server")=0 AND INSTR(C.OS,"microsoft")>0 AND LocationID = L.Name AND ClientName = Cl.Name AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Workstations Pending Reboots' THEN (C.Flags & 1024) = 1024 AND (C.lastcontact > DATE_ADD(NOW(),INTERVAL -7 DAY)) AND INSTR(C.OS,"server")=0 AND INSTR(C.OS,"microsoft")>0 AND LocationID = L.Name AND ClientName = C.Name AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Total Patch Workstations' THEN INSTR(C.os,"server")=0 AND INSTR(C.os,"microsoft")>0 AND LocationID = L.Name AND ClientName = CL.Name AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Servers Missing Patches' THEN INSTR(C.os,"server")>0

    J 1 Reply Last reply
    0
    • S SQL Ed

      The following code keeps erroring out in MySQL Workbench. I have not been able to locate the syntax problem. Can anyone see whats wrong with this code. Runnining the code a section at a time still dosn't work. It errors at the first ; where I placed the MAD face. Cannot completely remove the errors they just keep changing places. Also is there a good library of code snippets to view if needed? /* PATCH MANAGEMENT */ DELIMITER $$ #MachineType means Server or Workstation as determined by the word server in the os field DROP PROCEDURE IF EXISTS usp_cbi_PatchManagement$$ CREATE PROCEDURE usp_cbi_PatchManagement(MasterGrp varchar(30),Criteria varchar(30),LocationID varchar(30), ClientName varchar(30)) BEGIN SELECT IFNULL(COUNT(DISTINCT A.computerid),0) AS 'Dynamic Machine Counts' FROM (SELECT HF.computerid, HF.hotfixID FROM hotfixdata HFD INNER JOIN hotfix HF ON HF.hotfixid = HFD.hotfixid AND HFD.ignore <> 1 LEFT OUTER JOIN Computers AS C ON C.ComputerID=HF.ComputerID LEFT OUTER JOIN locations AS L ON C.LocationID=L.LocationID LEFT OUTER JOIN Clients AS CL ON C.ClientID=CL.ClientID JOIN agentcomputers AS AC ON C.ComputerID=AC.computerid JOIN mastergroups AS MG ON AC.groupid=MG.groupId #Enter Case When here seperating different where clauses. WHERE CASE WHEN Criteria = 'Workstations Missing Patches' THEN INSTR(C.os,"server")=0 AND INSTR(C.os,"microsoft")>0 AND HF.installed <> 1 AND HF.Approved = 1 AND LocationID = L.Name AND ClientName = Cl.Name :mad: AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Workstations with Empty Patch Tabs' THEN HF.hotfixid IS NULL AND (C.lastcontact > DATE_ADD(NOW(),INTERVAL -7 DAY)) AND INSTR(C.OS,"server")=0 AND INSTR(C.OS,"microsoft")>0 AND LocationID = L.Name AND ClientName = Cl.Name AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Workstations Pending Reboots' THEN (C.Flags & 1024) = 1024 AND (C.lastcontact > DATE_ADD(NOW(),INTERVAL -7 DAY)) AND INSTR(C.OS,"server")=0 AND INSTR(C.OS,"microsoft")>0 AND LocationID = L.Name AND ClientName = C.Name AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Total Patch Workstations' THEN INSTR(C.os,"server")=0 AND INSTR(C.os,"microsoft")>0 AND LocationID = L.Name AND ClientName = CL.Name AND MasterGrp = MG.Name AND MG.ParentID =0; WHEN Criteria = 'Servers Missing Patches' THEN INSTR(C.os,"server")>0

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #2

      A case when clause can only return values, not conditions.

      Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

      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