TSQL uupdate using row_number

Posted on 2008-11-14
Last Modified: 2012-05-05
i am trying to update using the query attached.
SoNo is a field in itemSO
i get this error :

Msg 4108, Level 15, State 1, Line 1
Windowed functions can only appear in the SELECT or ORDER BY clauses.

Could someone please explain why this is wrong, and tell me what could be a solution?
update itemSO

set ficAssmb = SoNo + '-' + ROW_NUMBER() OVER(PARTITION BY SoNo ORDER BY SoNo, itemNo)

Open in new window

Question by:Nyana22
    LVL 142

    Accepted Solution

    what is the primary key of your table, please?
    say it is named PK
    update t
    set ficAssmb = n.ficAssmb 
    from itemSO t
    join ( select pk, SoNo + '-' + ROW_NUMBER() OVER(PARTITION BY SoNo ORDER BY SoNo, itemNo) ficAssmb from itemSO ) n
     on =

    Open in new window

    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    to explain what is wrong: read the error message... in short the syntax is wrong, ie not supported.
    my suggestion will workaround that.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now