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, 10: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, 10: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, 10: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, 11:24 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
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, 11:40 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
Nelson:

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

Frank

Reply With Quote
  #6  
Old February 16th, 2006, 11:53 AM
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: 10
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




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek