|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Calculating intervals
How can I make a calculation on a given set of fields in a record as the record is written to the table?
Specifically, we have a set of test stands that are writing to the table. The frequency of when each stand writes logged data to the table can vary (every 10 seconds,every 30 seconds, etc.). The date and time when the data was logged are included as two fields. For each test stand I'd like to find the interval since the last time it wrote to the table. The interval calculation would occur every time a new row hit the table. Any suggestions are greatly appreciated!! |
|
#2
|
|||
|
|||
|
Use a trigger to do this on each insert. That's the easiest/most reliable way.
|
|
#3
|
|||
|
|||
|
Quote:
Nelson: Thanks for the quick reply. I'm a complete newbie at SQL. I don't know what a trigger is. Can you elaborate on your answer? Is it possible to set certain fields to contain calculations that depend on other fields (similar to Excel) or can a table contain only "dumb" data? Thanks again. |
|
#4
|
|||
|
|||
|
Frank,
Here's a defnition from MS-SQL Server Books Online(aka BOL) about triggers: "A trigger which is a special kind of stored procedure that executes automatically when a user attempts the specified data-modification statement on the specified table." Look up CREATE TRIGGER in this documentation for some examples. Once the event which causes the trigger to be fired happens(in this case the INSERT) you can then perform calculations on other fields. -Nelson Quote:
|
|
#5
|
|||
|
|||
|
Nelson:
I'll try CREATE TRIGGER. Thanks again, you've been a huge help! Frank |
|
#6
|
||||
|
||||
|
Is it necessary to store the calculated result?
You could just as easily calculate on your SELECT query. Example: SELECT qty, price, qty*price AS total FROM order_table;
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Calculating intervals |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|