如何根据从另一个表中选择的结果更新一个表中的列。

问题描述 投票:0回答:1

我需要帮助编写SQL Server 2008的脚本。

我有2张表。CharacterMEMB_INFO我想自动运行这段代码,作为一个SQL Server代理工作。

SELECT MasterResetCount
FROM character
WHERE MasterResetCount = 3 OR = 5 OR 7

并在同一段代码中添加类似 "IF "的内容。

只有当MasterResetCount=3或=5或7时,才会进行测试。

最新情况。

update MEMB_INFO 
set AccountLevel = 1

我很想得到帮助

我真的不懂写查询。

谢谢你!我需要你的帮助。

sql sql-server sql-server-2008 scripting sql-scripts
1个回答
0
投票

可以使用where子句,只在字符表存在MasterResetCount值为3、5、7的记录时才执行更新。

update MEMB_INFO set AccountLevel = 1
where exists (select *
              from character
              where character.UserId = MEMB_INFO.UserId and
                    MasterResetCount in (3, 5, 7))
© www.soinside.com 2019 - 2024. All rights reserved.