如果可能的话,我想知道如何组合这两个 UPDATE 语句以及这是否会节省性能。查询当前在 3 秒内执行,但将继续增长。
如果您在我的 CASE 和 WHERE 语句中知道更整洁、更优雅的过滤,则可以加分。
谢谢
DECLARE @PartRevision TABLE
(
OriginalPart VARCHAR(50) NULL,
PartNum VARCHAR(50) NULL,
Revision VARCHAR(50) NULL,
[Language] VARCHAR(50) NULL,
Hierarchy VARCHAR(50) NULL
)
INSERT INTO @PartRevision
(
OriginalPart,
PartNum,
Revision,
[Language],
Hierarchy
)
SELECT
part_no
,''
,''
,''
,''
FROM dbo.PartMaster
;
UPDATE @PartRevision
SET PartNum = SUBSTRING(OriginalPart,1,6)
,Revision = SUBSTRING(RIGHT(OriginalPart, LEN(OriginalPart) - 6),1,2)
,[Language] = CASE
WHEN LEN(RIGHT(OriginalPart, LEN(OriginalPart) - 6)) = 2 THEN ''
WHEN RIGHT(OriginalPart, LEN(OriginalPart) - 6) = 'DEV' THEN ''
ELSE RIGHT(RIGHT(OriginalPart, LEN(OriginalPart) - 6), (LEN(RIGHT(OriginalPart, LEN(OriginalPart) - 6)) -2))
END
FROM @PartRevision
--business designed/approved filter--
WHERE LEFT(OriginalPart, 1) NOT IN ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
AND OriginalPart NOT IN ('40T', '45T', '46AJ', '2044', '16NA', '12NA', '86TCE', '86TNA', '86TAS', '82TNA', '66TNA', '643TH', '843TH', '99000', '61TNA', '3215NA', '4626NA', '7127NA', '9250NA', '63AJNA', '1056TH', '8841NA', '3219NA', '1044TH', '3226NA', '4632NA', '4740NA', '8831NA', '208922', '7135NA', '85AJNA', '3220NA', '201975B', '201520A', '200989B', '109271B', '1044THS', '200465B', '202207A', '201436A', '2PREPAY', '200545A', '1056THS', '111169B', '30AJENA', '202204B', '202140B', '200551B', '201452B', '310142B', '2p5 ARA', '202100A', '111170B', '218999A', '1256THS', '202061B', '107212F', '202698A', '201974B', '201114B')
;
UPDATE @PartRevision
SET PartNum = CONCAT(PartNum, [Language])
FROM @PartRevision
;
SELECT * FROM @PartRevision