Reputation: 191
I have to create a query in which I have to find the last workingday in the previous month. I know how to do this with my date dimension that has an IsWorkingday
flag and joining to the date one month ago from today and from there find the max(dateid).
While I was doing this I was thinking shouldn't there be a more elegant solution like using LAG()
with a specific partition by and order by.
I played with it for a while but couldn't find a solution. Any ideas?
Upvotes: 0
Views: 508
Reputation: 31785
That's not really what LAG() is for. It's better suited for things like calculating a running total. Please google the LAG() function in SQL Server if you want a better understanding.
A possibly more elegant solution would be to get the first working day of the current month, and select the first working day before it.
Without knowing your table structure and data, it's hard to be more specific.
Upvotes: 1