Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
HI I want output like this

I have one column from the table

Date Time 
2013-12-17 14:41:00.000
2013-12-17 16:00:00.000
2013-12-17 16:29:00.000
2013-12-17 16:32:00.000
2013-12-17 17:54:00.000
2013-12-17 17:55:00.000


in 2nd column remove first record
Output should be like this

Date Time                                NewDatetime          
2013-12-17 14:41:00.000                  2013-12-17 16:00:00.000
2013-12-17 16:00:00.000                  2013-12-17 16:29:00.000
2013-12-17 16:29:00.000                  2013-12-17 16:32:00.000
2013-12-17 16:32:00.000                  2013-12-17 17:54:00.000
2013-12-17 17:54:00.000                  2013-12-17 17:55:00.000
2013-12-17 17:55:00.000


use first column as a second column but in diff is first row remove from first column and use this as a new datetime column

How to write a query for this.

thank you ,
Posted
Updated 3-Jan-14 1:59am
v2

1 solution

Hi,

This should help you.
SQL
A.Datetime,B.Datetime 
from 
 (select   ROW_NUMBER() OVER (ORDER BY Datetime) AS RowNumber,Datetime1 from table1 ) AS A 
LEFT JOIN 
 (select   ROW_NUMBER() OVER (ORDER BY Datetime) AS RowNumber,Datetime1 from table1) AS B 
    ON B.RowNumber = A.RowNumber+1


Please mark it as answer if it helps.
 
Share this answer
 
v2
Comments
RKparmar 3-Jan-14 8:18am    
Thank You .

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