Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

LAG with Dates #133

Open
GallegoRIvas opened this issue May 18, 2018 · 0 comments
Open

LAG with Dates #133

GallegoRIvas opened this issue May 18, 2018 · 0 comments

Comments

@GallegoRIvas
Copy link

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant