Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor Update, or Something Else?

Status
Not open for further replies.

dukeslater

Technical User
Jan 16, 2001
87
US
I have inserted data into a temp table such as this:

Emp Type Starttime Endtime
1 A 08:00
1 A 08:30
1 B 09:00
1 C 10:00
1 B 10:30

What is the best way to get the next starttime into the previous endtime:

Emp Type Starttime Endtime
1 A 08:00 08:30
1 A 08:30 09:00
1 B 09:00 10:00
1 C 10:00 10:30
1 B 10:30


Thanks for the help...
 
Include an Identity column in your temp table, and then do a self join.

Ex. Create Table #Blah(RowId Integer Identity(1,1), Emp Integer, Type VarChar(1), etc....)

Then

Select A.Emp,A.Type,A.StartTime, B.StartTime As EndTime
From #Blah As A
Inner Join #Blah As B On A.RowId = B.RowId - 1


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top