|
|
| No such thing as a small change | |
| PerlMonks |
Re: Searching (sybase) Database and SQL help (was: Neophyte needs help.)by BlueBlazerRegular (Friar) |
| on Jun 27, 2002 at 13:40 UTC ( [id://177790]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
To get this right, I'd normally need some more information on how the database tables are laid out. But for now, I'll just guess at the table layout and work from there. This solution assumes the following:
1) The table has all the past alarms ('warning' and 'ok now' messages). For example:
Topic Category DateTime
Process1 WARNING 06/25/2002 12:32:14.001
Process2 WARNING 06/25/2002 13:45:12.020
Process1 OK NOW 06/25/2002 13:56:12.050
Process3 WARNING 06/25/2002 14:10:01.123
Process2 OK NOW 06/25/2002 14:15:10.005
Process1 WARNING 06/25/2002 14:20:15.001
Process3 OK NOW 06/25/2002 14:32:10.005
Process2 WARNING 06/25/2002 14:46:45.001
2) You only want to see the latest alarm(s) for each process.
If the above assumptions are correct, then the following should get you close. The bulk of the effort is in the SQL statement...
This should get you the following results (using the sample data from above):
Process1 06/25/2002 14:20:15.001
Process2 06/25/2002 14:46:45.001
Process3 06/25/2002 14:10:01.123 06/25/2002 14:32:10.005
Of course, if the data is in a different layout, then this solution won't necessarily work.
And while we're here - a few comments about your code. First, congratulations on using '-w' and 'use strict' - they've saved my butt many times. But try not to use 'select *' in your SQL statements. Only pull the fields you need - you save memory that way and by explicitly requesting the fields you want you save yourself some heartbreak later on if someone adds columns to the table. And one final thing - indent your code. It's hard to tell where the 'foreach' statment ends when everything if pushed over to the left side.
Pat
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||