I am trying to declare variables and use it in my sql query as shown below but it gives me error:
-- this will get the the timestamp in seconds
DECLARE @startTimeStamp bigint = cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-09 16:22:17.897' ) as bigint)
DECLARE @endTimeStamp bigint = cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-10 16:22:17.897' ) as bigint)
-- my query.
SELECT processId,
houroftheday,
minuteofhour,
listagg(clientId, ',') within group (order by minuteofhour) as clientIds,
count(*) as psg
FROM data.process
where kite = 'BULLS'
and code is null
and timestampinepochsecond >= @startTimeStamp AND timestampinepochsecond < @endTimeStamp
group by 1, 2, 3
I read it here as it isn't possible so how can I rewrite my above query so that it can work fine? I tried their example but having issues in converting it out.
Below is what I have tried but I get syntax error:
CREATE TEMP TABLE tmp_variables AS SELECT
cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-09 16:22:17.897' ) as bigint) AS StartDate,
cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-10 16:22:17.897' ) as bigint) AS EndDate;
Here is my demo where it gives the error: