我想从#Table中获取“操作”字段中的一部分代码。我使用插入脚本创建了示例数据集。
Create Table #Tabel1 (Action varchar(1000));
Insert #Tabel1 (action) values ('ID573')
Insert #Tabel1 (action) values('ID573')
Insert #Tabel1 (action) values ('ID573 S00537 ZS08945L13')
Insert #Tabel1 (action) values ('T02276 ( F22 , CD5741 ; F23 , CD5731 )')
Insert #Tabel1 (action) values ('T02276 ( F22 , CD5740 ; F23 , CD5730 )')
Insert #Tabel1 (action) values ('ID581')
Insert #Tabel1 (action) values ('ID581')
Insert #Tabel1 (action) values ('ID581')
Insert #Tabel1 (action) values ('ID581')
Insert #Tabel1 (action) values ('ID581')
Insert #Tabel1 (action) values ('T02276 ( F22 , CD5821 ; F23 , CD5811 )')
Insert #Tabel1 (action) values ('T02276 ( F22 , CD5820 ; F23 , CD5810 )')
SELECT DISTINCT Substring (action, Patindex('%[D][0-9][0-9][0-9]%', action), 4)
AS Action
FROM #tabel1
WHERE action LIKE '%[D][0-9][0-9][0-9]%'
AND [action] NOT LIKE '%[I][D][0-9][0-9][0-9]%'
当前输出:
Action
D574
D582
预期输出:
Action
D573
D574
D582
D581
是否有一种简单的方法来获取样品输出?