Azure / Azure/usql

LAG with Dates

Open
#133 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
231
Forks
666
PR merge metrics
No merged PRs in 30d

Description

Hi
Probably I am not understanding LAG function, but looks like only works with "int" data types,
In my example "FolderDate" is a datetime data type, I am trying to create a SCD Type 2 using LAG and LEAD.

@WITH_LAG=
SELECT
*
,LAG(FolderDate, 1, 0) OVER(PARTITION BY BUS_STOP_NUMBER ORDER BY FolderDate DESC) AS Valid_From
//,LEAD(FolderDate, 1, 0) OVER(PARTITION BY BUS_STOP_NUMBER ORDER BY FolderDate DESC) AS Valid_To
FROM @ToInsert
;

**This is the error message :**
### Severity Code Description Project File Line Suppression State
Error E_CSC_USER_LAGLEADDEFAULTINVALIDTYPE: The "default value" argument of LAG or LEAD function has invalid type. Cannot convert int to DateTime?.
Description:
The "default value" argument of LAG or LEAD function must be of the same or compatible type as the function's result.
Resolution:
Change the argument so that it is of the expected type.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.