简体   繁体   English

根据选择语句更新列信息

[英]update column information based on select statment

i used this query in sql server 2008 to select number of rows from large number 我在sql server 2008中使用此查询从大量选择行数

(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 谢谢

You can use an updatable CTE: 您可以使用可更新的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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM