Click here to Skip to main content
16,009,068 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
NIK IN/OUT DATE
10026 1 2015-07-07 14:15:09.000
10026 0 2015-07-06 14:16:28.000
10026 1 2015-07-06 14:16:37.000
10026 0 2015-07-08 05:26:17.000

i want the result like below:

NIK DATE IN DATE OUT
10026 2015-07-07 14:15:09.000 null
10026 2015-07-06 14:16:28.000 2015-07-06 14:16:37.000
10026 null 2015-07-08 05:26:17.000

how to incorporate the same line based on field (in-out) using sql in sql server
Posted

1 solution

IF I understood correctly your requirement, I believe that using LAG and LEAD functions would be the easiest way.

Have a look at How to fetch data from the previous or next rows in the resultset[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900