Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Conditionnal lag/lead?

$
0
0

Hi,

is there a way to use the lag and lead function with conditional?

I want to get the next sales date where the date is not the same as the current row date.

When I have multiple sales the same day, the lag function will return the next row which is the same day...

in this case:

Customer   Date  Product...

A      2014-01-01   P1

A      2014-01-01   P1

A      2014-01-03   P1

Expected result:

Customer   Date  Product next date

A      2014-01-01   P1   2014-01-03

A      2014-01-01   P1  2014-01-03

A      2014-01-03   P1  NULL

so can I do this with the lag function? or do I have to do it the "old" way by using a sub select?

thanks.


Viewing all articles
Browse latest Browse all 23857

Trending Articles