LAG with Dates
- 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
Assessment
This issue has not been assessed yet.