Please check:
CREATE TABLE #test(col1 VARCHAR(15),col2 VARCHAR(15))
INSERT INTO #test VALUES
('0001','0001'),
('0002','0001'),
('0003','0002'),
('0004','0002'),
('0005','0003'),
('0006','0004'),
('0007','0005')
SELECT *,
IIF(CAST(col1 AS INT)-CAST(col2 AS INT)>=2,col1,NULL) temp
FROM #test
Output:
If you want to get all col1>col2 columns, please refer to:
SELECT *,
IIF(CAST(col1 AS INT)>CAST(col2 AS INT),col1,NULL) temp
FROM #test
Output:
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".