WITH TEST AS (
SELECT '202201' [STWEK],'202201' [Z1WEK] UNION ALL
SELECT '202202' [STWEK],'202202' [Z1WEK] UNION ALL
SELECT '202203' [STWEK],'202203' [Z1WEK] UNION ALL
SELECT '202204' [STWEK],'202204' [Z1WEK] UNION ALL
SELECT '202205' [STWEK],'202205' [Z1WEK] UNION ALL
SELECT '202206' [STWEK],'202206' [Z1WEK] UNION ALL
SELECT '202207' [STWEK],'202207' [Z1WEK] UNION ALL
SELECT '202208' [STWEK],'202208' [Z1WEK] UNION ALL
SELECT '202209' [STWEK],'202209' [Z1WEK] UNION ALL
SELECT '202210' [STWEK],'202210' [Z1WEK] UNION ALL
SELECT '202211' [STWEK],'202211' [Z1WEK] UNION ALL
SELECT '202212' [STWEK],'202212' [Z1WEK] UNION ALL
SELECT '202213' [STWEK],'202213' [Z1WEK] UNION ALL
SELECT '202214' [STWEK],'202214' [Z1WEK] UNION ALL
SELECT '202215' [STWEK],'202215' [Z1WEK] UNION ALL
SELECT '202216' [STWEK],'202216' [Z1WEK] UNION ALL
SELECT '202217' [STWEK],'202217' [Z1WEK] UNION ALL
SELECT '202218' [STWEK],'202218' [Z1WEK] UNION ALL
SELECT '202219' [STWEK],'202219' [Z1WEK] UNION ALL
SELECT '202220' [STWEK],'202220' [Z1WEK] UNION ALL
SELECT '202221' [STWEK],'202221' [Z1WEK] UNION ALL
SELECT '202222' [STWEK],'202222' [Z1WEK] UNION ALL
SELECT '202223' [STWEK],'202223' [Z1WEK] UNION ALL
SELECT '202224' [STWEK],'202224' [Z1WEK] UNION ALL
SELECT '202225' [STWEK],'202225' [Z1WEK] UNION ALL
SELECT '202226' [STWEK],'202226' [Z1WEK] UNION ALL
SELECT '202227' [STWEK],'202227' [Z1WEK] UNION ALL
SELECT '202228' [STWEK],'202228' [Z1WEK] UNION ALL
SELECT '202229' [STWEK],'202229' [Z1WEK] UNION ALL
SELECT '202230' [STWEK],'202230' [Z1WEK] UNION ALL
SELECT '202231' [STWEK],'202231' [Z1WEK] UNION ALL
SELECT '202232' [STWEK],'202232' [Z1WEK] UNION ALL
SELECT '202233' [STWEK],'202233' [Z1WEK] UNION ALL
SELECT '202234' [STWEK],'202234' [Z1WEK] UNION ALL
SELECT '202235' [STWEK],'202235' [Z1WEK] UNION ALL
SELECT '202236' [STWEK],'202236' [Z1WEK] UNION ALL
SELECT '202237' [STWEK],'202237' [Z1WEK] UNION ALL
SELECT '202238' [STWEK],'202238' [Z1WEK] UNION ALL
SELECT '202239' [STWEK],'202239' [Z1WEK] UNION ALL
SELECT '202240' [STWEK],'202240' [Z1WEK] UNION ALL
SELECT '202241' [STWEK],'202241' [Z1WEK] UNION ALL
SELECT '202242' [STWEK],'202242' [Z1WEK] UNION ALL
SELECT '202243' [STWEK],'202243' [Z1WEK] UNION ALL
SELECT '202244' [STWEK],'202244' [Z1WEK] UNION ALL
SELECT '202245' [STWEK],'202245' [Z1WEK] UNION ALL
SELECT '202246' [STWEK],'202246' [Z1WEK] UNION ALL
SELECT '202247' [STWEK],'202247' [Z1WEK] UNION ALL
SELECT '202248' [STWEK],'202248' [Z1WEK] UNION ALL
SELECT '202249' [STWEK],'202249' [Z1WEK] UNION ALL
SELECT '202250' [STWEK],'202250' [Z1WEK] UNION ALL
SELECT '202253' [STWEK],'202251' [Z1WEK] UNION ALL
SELECT '202301' [STWEK],'202252' [Z1WEK] UNION ALL
SELECT '202302' [STWEK],'202253' [Z1WEK]
)
SELECT * FROM TEST WHERE STWEK= (
case when (CONVERT(BIGINT,(right(Z1WEK,2)))+2)>DATEPART(WW,CONCAT(LEFT(Z1WEK,4),'-12-31'))
then CONCAT(CONVERT(BIGINT,(LEFT(Z1WEK,4)))+1,(CONVERT(BIGINT,(right(Z1WEK,2))))+2)-DATEPART(WW,CONCAT(LEFT(Z1WEK,4),'-12-31'))
ELSE CONVERT(BIGINT,(Z1WEK))+2 end )