使用 SQL 查询更新列数据

Update column data using SQL query

在我们的 SQL 服务器数据库中,我们正在尝试更新 table 中的旧列数据。 table 中有很多类似于 Agency Administrator 的数据。这是旧格式的数据,我们在列中取单个值。现在,由于数据结构的更新,我们将数据存储为 ["Agency Administrator"]。我们想在旧数据中做同样的更改,如 ["Agency Administrator"]。我们如何通过 SQL 查询进行更新?

期望的结果应该是 机构管理员 ---> ["Agency Administrator"]

这是你想要的吗?

update mytable
set adminType = '["Agency Administrator"]'
where adminType = 'Agency Administrator'

这会将 adminType 列中等于 'Agency Administrator' 的所有值替换为 '["Agency Administrator"]'

使用以下代码进行测试:

create table test(RequestId int,AdminType varchar(100));
insert into test values(2328,'Agency Administrator')
insert into test values(2299,'Agency Clerk')
select * from test;
UPDATE test SET AdminType = CONCAT('["', AdminType,'"]')