你可以用一個簡單的UPDATE
使用CASE
表達式做到這一點:
UPDATE mytable
SET
Duration1 = CASE WHEN Duration1 IS NOT NULL THEN I1 ELSE Duration1 END
, Duration2 = CASE WHEN Duration1 IS NULL AND Duration2 IS NOT NULL THEN I2 ELSE Duration2 END
, Duration3 = CASE WHEN Duration1 IS NULL AND Duration2 IS NULL AND Duration3 IS NOT NULL THEN I3 ELSE Duration3 END
-- Continue in the same boring way
, Duration10 = CASE WHEN Duration1 IS NULL AND Duration2 IS NULL AND Duration3 IS NULL AND Duration4 IS NULL AND Duration5 IS NULL AND Duration6 IS NULL AND Duration7 IS NULL AND Duration8 IS NULL AND Duration9 IS NULL AND Duration10 IS NOT NULL THEN I10 ELSE Duration10 END
請添加一些DDL或文字,圖片被阻擋在某些領域 – TheGameiswar