Putting aside the form in which the client expects to receive the data, a better way would be to combine the two resultsets into one:
IF EXISTS (SELECT *
FROM master_list
WHERE code = 'r_params')
BEGIN
UPDATE master_list
SET code = 'w_params'
WHERE code = 'r_params'
AND name_1 <> 'pH'
AND name_2 <> 'Flow'
AND name_3 <> 'Temperature'
SELECT *
FROM r_master_list
WHERE code IN ('r_params', 'w_params')
END
This way you are making ONE query on r_master_list
rather than two. The client will receive the exact same data; only it will be his responsibility to split it into distinct resultsets, should he need to. Performance and efficiency-wise, that should be the preferred solution.
UPDATE:
As Drew suggests you may also want to make your `EXISTS' function subquery like this instead:
IF EXISTS (SELECT 1
FROM master_list
WHERE code = 'r_params')
There is quite a debate over this being more efficient or not. Drew seems to believe it is; I for one can't tell. BUT! There's still an advantage with this approach that Drew didn't mention: if you ever want to find SELECT
queries using *
for fields throughout your codebase, you will find it convenient that all of your EXISTS
functions subqueries uses the SELECT 1
pattern so that you won't reach out to those needlessly. It may not be much but still I thought it was worth mentionning.