> To reproduce #2
Alas, we could not reproduce this bug in this situation and with these very settings.
But we reproduced a similar bug in several other situations, and we will fix it.
> As for my #3
I have logged this in our internal tracking system as a suggestion.
> Let add a #4
Here is what I've got after formatting.
Code: Select all
SELECT dbo.fUtilConvertToSTD(dateadd(s, (datediff(s, '1/1/2000', dbo.fUtilConvertToDST(td.trend_data_time, @tz, @enable_dst)) / @compress_by) * @compress_by, '1/1/2000'), @tz, @enable_dst) [TIME]
, sum(
CASE
WHEN m.measurement_type_id IN (4, 18) THEN
td.trend_data_avg * td.trend_data_interval
ELSE
NULL
END) / sum(
CASE
WHEN m.measurement_type_id IN (4, 18) THEN
td.trend_data_interval
ELSE
NULL
END) [DEPTH (in)]
, sum(
CASE
WHEN m.measurement_type_id IN (3, 17) THEN
td.trend_data_avg * td.trend_data_interval
ELSE
NULL
END) / sum(
CASE
WHEN m.measurement_type_id IN (3, 17) THEN
td.trend_data_interval
ELSE
NULL
END) [VELOCITY (fps)]
, sum(
CASE
WHEN m.measurement_type_id IN (2, 16) THEN
td.trend_data_avg * td.trend_data_interval
ELSE
NULL
END) / sum(
CASE
WHEN m.measurement_type_id IN (2, 16) THEN
td.trend_data_interval
ELSE
NULL
END) [FLOW (mgd)]
, sum(
CASE
WHEN m.measurement_type_id IN (2, 16) THEN
td.trend_data_avg * td.trend_data_interval / 86400
ELSE
NULL
END) [CUMM FLOW (mg)]
, sum(
CASE
WHEN m.measurement_type_id IN (6) THEN
td.trend_data_avg
ELSE
NULL
END) [RAIN (in)]
FROM
dbo.measurements m
INNER JOIN dbo.trend_data td
ON m.measurement_id = td.measurement_id
WHERE
m.measurement_id IN (SELECT mid
FROM
@mids)
AND td.trend_data_time >= @starttime
AND td.trend_data_time < @endtime
GROUP BY
dbo.fUtilConvertToSTD(dateadd(s, (datediff(s, '1/1/2000', dbo.fUtilConvertToDST(td.trend_data_time, @tz, @enable_dst)) / @compress_by) * @compress_by, '1/1/2000'), @tz, @enable_dst)
ORDER BY
[TIME]
Of course, I used default settings and did not change anything. The only problem we can see is a long line that was not formatted, i.e. the “dbo.fUtilConvertToSTD(dateadd(s, (datediff …” line. Maybe we should consider adding more options in such cases. If you have any suggestions concerning formatting of this script, please tell us.
Also we plan to add some predefined formatting templates to avoid setting such a great amount of options manually.