I have a query that I need to convert to Databricks SQL or run against a table in a Databrick environment but failing even though it works very well against tables SQL Server. The tables and query can be found here
The query to convert or run in Databricks environment is:
;WITH CTE AS (
SELECT EventID
, EventName
, EventStartDateTime
, IIF(EventEndDateTime = '',GETUTCDATE(),EventEndDateTime)
AS EventEndDateTime
FROM EventLog
UNION ALL
SELECT EventID
, EventName
, DATEADD(month, DATEDIFF(month, 0, DATEADD(month , 1 ,
EventStartDateTime)), 0) AS EventStartDateTime
, EventEndDateTime
FROM CTE
WHERE DATEADD(month, DATEDIFF(month, 0, DATEADD(month , 1 ,
EventStartDateTime)), 0) <= EventEndDateTime
)
And then selecting from the CTE like so:
SELECT EventID
, EventName
, YEAR(EventStartDateTime)
, DATENAME(MONTH,EventStartDateTime)
, DATEDIFF(SECOND, EventStartDateTime, n_EventStartDateTime) /
3600.0
FROM (
SELECT EventID
, EventName
, EventStartDateTime
, LEAD(EventStartDateTime,1,EventEndDateTime)
OVER(PARTITION BY EventID,EventName ORDER BY
EventStartDateTime) n_EventStartDateTime
FROM CTE
) t1
OPTION (maxrecursion 0)
I equally noticed that
DATEADD(month, DATEDIFF(month, 0, DATEADD(month , 1 ,
EventStartDateTime)), 0) AS EventStartDateTime
and
DATEDIFF(SECOND, EventStartDateTime, n_EventStartDateTime) / 3600.0
are not working in databricks environment.
I sincerely appreciate your help on this