DECLARE @result float -- if you are certain there is only one record per condition (primary key constraints or something -- you can omit this statement and the IF..ELSE block /* SET @result = (SELECT COUNT(*) FROM Calculation D INNER JOIN Lookup_table L ON D.SUM_xi = L.SUM_xi WHERE (D.SUM_xi < 13) AND (D.Key_m = @Count_me)); */ -- try this instead SET @result = (SELECT COUNT(*) FROM Calculation D WHERE (D.SUM_xi < 13) AND (D.Key_m = @Count_me)); IF(@result = 1) begin SET @result = (SELECT D.SUM_wixi + SQRT(D.SUM_wi2xi / D.SUM_xi) * (L.c - L.SUM_xi) FROM Calculation D INNER JOIN Lookup_table L ON D.SUM_xi = L.SUM_xi WHERE (D.SUM_xi < 13) AND (D.Key_m = @Count_me)); UPDATE Calculation SET Lower_95 = @result, Lower_95_Calc_method = 'UPDATE' WHERE SUM_xi < 13 AND Key_m = @Count_me; SET @Count_me = @Count_me + 1; end ELSE begin -- do something here to indicate multiple or zero records returned end