Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Query for Null, Zero, and Constant Data
    primarykey
    data
    text
    <p>I have a query and I just want to modify it (This query is not written by me).</p> <pre><code>SELECT CAST(DATEPART(yyyy, UTCTimeStamp) AS VARCHAR(4)) + '-' + CAST(DATEPART(mm, UTCTimeStamp) AS VARCHAR(2)) + '-' + CAST(DATEPART(dd, UTCTimeStamp) AS VARCHAR(2)) + ' ' + CAST(DATEPART(hh, UTCTimeStamp) AS VARCHAR(2)) + ':00:000 - ' + CAST(DATEPART(yyyy, UTCTimeStamp) AS VARCHAR(4)) + '-' + CAST(DATEPART(mm, UTCTimeStamp) AS VARCHAR(2)) + '-' + CAST(DATEPART(dd, UTCTimeStamp) AS VARCHAR(2)) + ' ' + CAST(DATEPART(hh, UTCTimeStamp) AS VARCHAR(2)) + ':45:000' AS HourTime , SUM(CASE WHEN ElapsedValue IS NULL THEN 1 ELSE 0 END) AS NoData , SUM(CASE WHEN ElapsedValue = 0 THEN 1 ELSE 0 END) AS ZeroData FROM tblLive_TrendLog_15Min WHERE ISNULL(ElapsedValue, 0) = 0 GROUP BY CAST(DATEPART(yyyy, UTCTimeStamp) AS VARCHAR(4)) + '-' + CAST(DATEPART(mm, UTCTimeStamp) AS VARCHAR(2)) + '-' + CAST(DATEPART(dd, UTCTimeStamp) AS VARCHAR(2)) + ' ' + CAST(DATEPART(hh, UTCTimeStamp) AS VARCHAR(2)) + ':00:000 - ' + CAST(DATEPART(yyyy, UTCTimeStamp) AS VARCHAR(4)) + '-' + CAST(DATEPART(mm, UTCTimeStamp) AS VARCHAR(2)) + '-' + CAST(DATEPART(dd, UTCTimeStamp) AS VARCHAR(2)) + ' ' + CAST(DATEPART(hh, UTCTimeStamp) AS VARCHAR(2)) + ':45:000' </code></pre> <p>When I run this query, it is going to display: </p> <pre><code>HourlyTime ZeroData NULL 2013-6-8 23:00:000 - 2013-6-8 23:45:000 0 40 2013-6-8 3:00:000 - 2013-6-8 3:45:000 0 52 2013-6-8 7:00:000 - 2013-6-8 7:45:000 0 52 2013-6-9 3:00:000 - 2013-6-9 3:45:000 0 52 2013-6-9 4:00:000 - 2013-6-9 4:45:000 0 52 2010-1-1 12:00:000 - 2010-1-1 12:45:000 0 36 2010-1-1 13:00:000 - 2010-1-1 13:45:000 0 27 2010-1-1 15:00:000 - 2010-1-1 15:45:000 0 30 </code></pre> <p>Basically it is calculating the zero and null values per hour. If you want to know more about it this is the link: <a href="https://stackoverflow.com/questions/17327835/sql-programming-combining-4-rows-into-1-and-adding-3-columns">SQL Programming combining 4 rows into 1 and adding 3 columns</a></p> <p>Now, I just want to add another column to that query that would calculate if there are any constant values then just display the number of the constant values (should be between 0 and 3) for example if the value at 2013-05-4 10:30 has the same value at 2013-05-4 10:15 then should be 1 in the ConstantData column. basically, compare the value to the previous value every 15 minutes. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload