Create Auto Number based on ORder by Field

  • Hi Guys - This should be an easy one but need to confirm.

    I need to alter a table and create Auto Number based on Order By ASCENDING a field which is a 13 digit numbers.

    I normally use:

    Alter Table [TableNAME]

    add AutoNum Numeric(5,0) identity

    But the above does not like ORder By statement,.

    Please guide as soon as possible.

    Thanks in Advance

  • arun_anand09 (4/16/2009)


    But the above does not like ORder By statement,.

    Could you clarify what you mean by this statement?

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • In order to accomplish what you're looking for you need to create a new empty table with the autonumber, then run an INSERT statement with the ORDER BY instruction attached. This will ensure that the data gets numbered appropriately.

    You will then need to do whatever table rename is relevant.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • I am curios to know why do you want to store the "Oder by" in table.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply