【发布时间】:2021-02-10 08:12:35
【问题描述】:
create table #test
(
id int,
section char(2),
seq int,
caseID int,
Modal varchar(10),
value1 varchar(10),
value2 varchar(10),
CustName varchar(10),
donedate datetime
);
insert into #test
values (1035, 'A1', 902, 408, 'Ind', 'firstTime', 'valtyp1', 'templerun', '2020-10-23')
insert into #test
values (1035, 'A1', 903, 408, 'Ind', 'secondtime', 'valtyp2', 'templerun', '2020-10-23')
insert into #test
values (3144, 'A1', 901, 801, 'Ind', NULL, 'valtyp1', 'templerun', '2020-10-23')
select * from #test
退货
+------+---------+-----+--------+-------+------------+---------+-----------+------------+
| id | section | seq | caseID | Modal | value1 | value2 | CustName | donedate |
+------+---------+-----+--------+-------+------------+---------+-----------+------------+
| 1035 | A1 | 902 | 408 | Ind | firstTime | valtyp1 | templerun | 10/23/2020 |
| 1035 | A1 | 903 | 408 | Ind | secondtime | valtyp2 | templerun | 10/23/2020 |
| 3144 | A1 | 901 | 801 | Ind | | valtyp1 | templerun | 10/23/2020 |
+------+---------+-----+--------+-------+------------+---------+-----------+------------+
在这里,我尝试使用其他相同类型的行/记录来更新 Value1、value2 列。示例:
- 在第一行:value1 = 'firstTime secondtime' & value2= 'valtyp1 valtyp2'
- 在第二行:value1 = 'secondtime firstTime' & value2= 'valtyp2 valtyp1'
其中 'seq' 有不同的值。
谁能解释一下如何编写一个查询来连接/更新同一列的另一行。
【问题讨论】:
标签: sql sql-server sql-server-2008 sql-server-2012