Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 16th, 2006, 11:05 AM
Frank V Frank V is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: Toronto
Posts: 6 Frank V User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 51 sec
Reputation Power: 0
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!!

Reply With Quote
  #2  
Old February 16th, 2006, 11:23 AM
nelsonha nelsonha is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Location: Bethesda, MD USA
Posts: 2 nelsonha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 11 m 6 sec
Reputation Power: 0
Use a trigger to do this on each insert. That's the easiest/most reliable way.

Reply With Quote
  #3  
Old February 16th, 2006, 11:54 AM
Frank V Frank V is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: Toronto
Posts: 6 Frank V User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 51 sec
Reputation Power: 0
Quote:
Originally Posted by nelsonha
Use a trigger to do this on each insert. That's the easiest/most reliable way.


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.

Reply With Quote
  #4  
Old February 16th, 2006, 12:24 PM
nelsonha nelsonha is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Location: Bethesda, MD USA
Posts: 2 nelsonha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 11 m 6 sec
Reputation Power: 0
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:
Originally Posted by Frank V
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.

Reply With Quote
  #5  
Old February 16th, 2006, 12:40 PM
Frank V Frank V is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: Toronto
Posts: 6 Frank V User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 51 sec
Reputation Power: 0
Nelson:

I'll try CREATE TRIGGER. Thanks again, you've been a huge help!

Frank

Reply With Quote
  #6  
Old February 16th, 2006, 12:53 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Calculating intervals


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT