现在的位置: 首页 > 综合 > 正文

Sql 更新所有满足条件记录里第一条记录

2012年12月17日 ⁄ 综合 ⁄ 共 272字 ⁄ 字号 评论关闭

我的办法是选出第一条记录Select top 1,然后选取表中其它几个列名,这几个字段的值决定该条记录是唯一的。

通过这些字段来更新对应行的记录。

update pub_p_templated set id =id+ " + i + " where (templateid=   ( select top 1 templateid from pub_p_templated where id=1) and itemid =(select top 1 itemid from pub_p_templated where id=1 ))"

这里选的字段是templateid和itemid

 

如果你有更好的办法就请教一下。

抱歉!评论已关闭.