DECLARE @i int = 2880 WHILE @i < 12000 BEGIN SET @i = @i + 1 IF not EXISTS(SELECT ID FROM dbo.OtherProperties WHERE Dom_ID = 689 AND Code = @i) begin insert into dbo.OtherProperties(ID,Code,Dom_ID,Value) values ((select MAX(ID)+1 from dbo.OtherProperties),@i,689,(select dbo.ConvertToTime(@i))) end END