title: Calculating Machine Status Time in SQL
body: <p>I have a simple SQL express server set up and am logging data to it, I have multiple machines (industrial machinery) I am monitoring. Whenever the machines status changes I create a new record which enters data in the following columns. Time (Time Stamp), Machine Name (Text), Status (1,2, or 3) for running, idle, and down, and ReasonCode (1-10). I need to calculate how long the machine was in each status and also the reason for each status.  I would like to make this available via SQL reports. This is a function that A LOT of industrial manufactures are looking to do these days and I am trying to create a simple example. Unfortunately I am not that versed with SQL. I imagine this could be put in a stored procedure and run every n seconds to re calculate. Any help would be most appreciated. </p>