• riya_dave (8/2/2013)


    but i dont need select ,i just need update statement, the store proc should not have select

    So turn the select into an update. 😉

    ;with SortedData as

    (

    select cc.*, s.SortOrder, ROW_NUMBER() over(partition by ID order by s.SortOrder) as RowNum

    from CustomCode cc

    left join #SortSomething s on cc.pcondition = s.pcondition

    )

    update SortedData

    set pcondition = case when RowNum = 1 AND SortOrder is not null then pcondition else null end,

    Pinten = case when RowNum = 1 AND SortOrder is not null then Pinten else null end,

    scondition = case when RowNum > 1 then pcondition

    when RowNum = 1 AND SortOrder is null then scondition

    else null end ,

    sinten = case when RowNum > 1 then Pinten

    when RowNum = 1 AND SortOrder is null then sinten

    else null end

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/