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. Count errors and not display any less than a value

Count errors and not display any less than a value

Scheduled Pinned Locked Moved Database
cssdatabasehelp
5 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
    solutionsville
    wrote on last edited by
    #1

    I have this query that works as it is. I want to modify it so that I do not see Alarm errors less than 50. I guess it would have to be a sub query to this; SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate FROM AlarmsList where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY' GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111) Thanks,

    P 1 Reply Last reply
    0
    • S solutionsville

      I have this query that works as it is. I want to modify it so that I do not see Alarm errors less than 50. I guess it would have to be a sub query to this; SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate FROM AlarmsList where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY' GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111) Thanks,

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      Try this:

      SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate
      FROM AlarmsList
      where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY'
      GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111)
      HAVING COUNT(AlarmMessage) >= 50

      Adding the HAVING clause modifies the query so that only rows with an alarm message count >=50 are included in the output.

      Paul Marfleet

      S 1 Reply Last reply
      0
      • P pmarfleet

        Try this:

        SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate
        FROM AlarmsList
        where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY'
        GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111)
        HAVING COUNT(AlarmMessage) >= 50

        Adding the HAVING clause modifies the query so that only rows with an alarm message count >=50 are included in the output.

        Paul Marfleet

        S Offline
        S Offline
        solutionsville
        wrote on last edited by
        #3

        Thanks Paul. That did the trick. Boy was that simple!

        P 1 Reply Last reply
        0
        • S solutionsville

          Thanks Paul. That did the trick. Boy was that simple!

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          Thanks. The important thing to remember here is that the WHERE and HAVING clauses provide different ways of filtering the output of a query. A WHERE clause is used to filter non-aggregated data. A HAVING clause is used in conjunction with a GROUP BY clause to filter data aggregated in that GROUP BY clause.

          Paul Marfleet

          S 1 Reply Last reply
          0
          • P pmarfleet

            Thanks. The important thing to remember here is that the WHERE and HAVING clauses provide different ways of filtering the output of a query. A WHERE clause is used to filter non-aggregated data. A HAVING clause is used in conjunction with a GROUP BY clause to filter data aggregated in that GROUP BY clause.

            Paul Marfleet

            S Offline
            S Offline
            solutionsville
            wrote on last edited by
            #5

            Thank You. It is always a good day when you learn something new! Regards, Brian

            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