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

SQL Syntax 1

Status
Not open for further replies.

jchewsmith

Technical User
Nov 20, 2006
161
US
I am trying to update a field with a sequential number based on a order#. I only want to the number to increase in value when the order# changes.

Declare field at 999-000 add one every time the Order No changes

Order No Field to Update
123 999-001
123 999-001
123 999-001
456 999-002
456 999-002
789 999-003
234 999-004
234 999-004
345 999-005


 
Use a correlated sub-query to count distinct OrderNo's up to this row's OrderNo.

SQL:
update tablename t1
    set toUpdate = (select count(distinct order) from tablename t2
                    where t2.OrderNo <= t1.OrderNo)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top