Hossam Alkhalili
Hossam Alkhalili

Reputation: 17

update column information based on select statment

i used this query in sql server 2008 to select number of rows from large number

(select *
from (select *,
             row_number() over (partition by 
                     [Patient Family registration no# رقم الملف] order by ((CONVERT(date,[date of visit] ) ))) as seqnum
      from MFC  
      ) t
where  seqnum = 1)

now i need to update column call (type of visit) to be 'new visit' for these rows that i selected, how can i do that?? thanks

Upvotes: 0

Views: 28

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269803

You can use an updatable CTE:

with toupdate as (
      select mfc.*,
             row_number() over (partition by [Patient Family registration no# رقم الملف]
                                order by CONVERT(date, [date of visit] )
                               ) as seqnum
      from MFC  
     )
update toupdate
    set TypeOfVisit = 'New Visit'
    where seqnum = 1;

Upvotes: 2

Related Questions