Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

Pass date to cte through reporting services report

$
0
0

I have the following situation, I have a report that works great! and the user can put a date into the parameter and it will produce the report, but can i also get that date put into the cte?...my 2 query's are below, i really like this cte as it will provide a total that i need for the dashboard i am building.

1.  User enter a date on the report, and this query runs;

SELECT     TOP (100) PERCENT { fn HOUR(DateTime) } AS TIME, AVG(CASE WHEN TagName = 'Keller_Hypochlorite_Area.NaOCL_Tnk1_Lvl_Gal' THEN [Value] END)
                       AS [Keller HypoChlorite Tank1]
FROM         dbo.v_AnalogHistory
WHERE     (DateTime BETWEEN DATEADD(dd, 0, DATEDIFF(dd, 0, @DateParam1)) AND DATEADD(ss, 59, DATEADD(mi, 59, DATEADD(hh, 23, DATEADD(dd, 0, 
                      DATEDIFF(dd, 0, @DateParam1)))))) AND (wwResolution = 60000) AND (TagName = N'Keller_Hypochlorite_Area.NaOCL_Tnk1_Lvl_Gal')
GROUP BY { fn HOUR(DateTime) }
ORDER BY TIME

I have gotten this cte to work;

WITH CTE AS (

SELECT    TOP (100) PERCENT  { fn HOUR(DateTime) } AS TIME, AVG(CASE WHEN TagName = 'Keller_Hypochlorite_Area.NaOCL_Tnk1_Lvl_Gal' THEN [Value] END)
                       AS [Keller HypoChlorite Tank1]
FROM         dbo.v_AnalogHistory
WHERE     (DateTime = CONVERT(DATETIME, '2015-06-11 00:00:00', 102) AND DateTime <= CONVERT(DATETIME, '2015-06-11 23:59:59', 102)) AND 
                      (wwResolution = 900000) AND (TagName = N'Keller_Hypochlorite_Area.NaOCL_Tnk1_Lvl_Gal')
GROUP BY { fn HOUR(DateTime) }
ORDER BY TIME

)
SELECT  CTE.TIME, prev.[Keller HypoChlorite Tank1]  as PreviousValue,
CTE.[Keller HypoChlorite Tank1],
Case when prev.[Keller HypoChlorite Tank1] IS NULL then 0 
when CTE.[Keller HypoChlorite Tank1] < prev.[Keller HypoChlorite Tank1] then prev.[Keller HypoChlorite Tank1]-CTE.[Keller HypoChlorite Tank1]
Else 0 end as Calculateresult

FROM CTE
LEFT JOIN CTE prev ON prev.TIME = CTE.TIME - 1

but would like to use the following in the date field in the cte, is this possible?....thanks

BETWEEN DATEADD(dd, 0, DATEDIFF(dd, 0, @DateParam1)) AND DATEADD(ss, 59, DATEADD(mi, 59, DATEADD(hh, 23, DATEADD(dd, 0, DATEDIFF(dd, 0, @DateParam1)))))


Mark Jankowski


Viewing all articles
Browse latest Browse all 10045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>