I have a SQL query which shows time activity of each user. Database is Microsoft SQL Server on Windows Server 2008. This query works in SQL Server 2008. But when I connecting to SQL Server and use the query in tableau, request does not work.
There are parameters Parameters.Date1
and Parameters.Date2
on
my worksheet in tableau. I would like to use Parameters.Date1
and Parameters.Date2
instead
of @time
.
Help me please with changing this query, in order to it works in tableau with using of parameters Parameters.Date1
and Parameters.Date2
instead
of @time
.
The result of the query:
USER,Date,Total time
USER1,2016-09-22,07:00:00.0000000
USER2,2016-09-22,08:00:00.0000000
USER3,2016-09-22,05:00:00.0000000
SQL query:
DECLARE@time datetimeset@time ='08.09.2016'SELECT[User],
CAST(DATEADD(SECOND, sum(datediff(DAY,@time,[Start])),@time)AS date)'Date',
CAST(DATEADD(SECOND, sum(datediff(SECOND,'00:00:00',[Period])),'00:00:00')AS time)'Total time'FROM[User].[dbo].[UserAction]WHERE[Start]>=@time+'00:00:00'and[Start]<=@time+'23:59:59'GROUPBY[USER]
input data to build the query:
USER,Start,End,Period
USER1,2016-09-2209:00:00.000,2016-09-2212:00:00.000,03:00:00
USER1,2016-09-2212:00:00.000,2016-09-2213:00:00.000,01:00:00
USER1,2016-09-22,13:00:00.000,2016-09-2216:00:00.000,03:00:00
USER2,2016-09-22,09:00:00.000,2016-09-2213:00:00.000,04:00:00
USER2,2016-09-22,13:00:00.000,2016-09-2217:00:00.000,04:00:00
USER3,2016-09-22,09:00:00.000,2016-09-2210:00:00.000,01:00:00
USER3,2016-09-22,10:00:00.000,2016-09-2212:00:00.000,02:00:00
USER3,2016-09-22,12:00:00.000,2016-09-2214:00:00.000,02:00:00