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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update query question

Status
Not open for further replies.

heidi88

Programmer
May 1, 2003
32
0
0
US
Hi,

I need to update some records.

[BEFORE UPDATE]

CustNum OrderId startdt enddt InitOrderId
123 1 01/01/00 01/01/01
123 2 01/01/01 01/01/02
123 3 01/01/02 01/01/03

123 4 09/01/03 09/01/04
123 5 09/01/04 09/01/05
123 6 09/01/05 09/01/06
....

[AFTER UPDATE]

CustNum OrderId startdt enddt InitOrderId
123 1 01/01/00 01/01/01 NULL
123 2 01/01/01 01/01/02 1
123 3 01/01/02 01/01/03 1

123 4 09/01/03 09/01/04 NULL
123 5 09/01/04 09/01/05 5
123 6 09/01/05 09/01/06 6
...

I prefer not to use cursor. If anyone has any idea on how to update the initorderid field using set-based statement, that will be great.

Thanks a lot.
 
Sorry, type error:

[BEFORE UPDATE]

CustNum OrderId startdt enddt InitOrderId
123 1 01/01/00 01/01/01
123 2 01/01/01 01/01/02
123 3 01/01/02 01/01/03

123 4 09/01/03 09/01/04
123 5 09/01/04 09/01/05
123 6 09/01/05 09/01/06
....

[AFTER UPDATE]

CustNum OrderId startdt enddt InitOrderId
123 1 01/01/00 01/01/01 NULL
123 2 01/01/01 01/01/02 1
123 3 01/01/02 01/01/03 1

123 4 09/01/03 09/01/04 NULL
123 5 09/01/04 09/01/05 4
123 6 09/01/05 09/01/06 4
 
what criteria is used to update the InitOrderId column ?

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Trying to link continous records back to the original one. If 1st startdt= 2nd enddt, 2nd startdt = 3 enddt...mark the initorderid to the very first record.

Heidi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top