I am using Sql Server 2008. In my sql file, I have defined 5 local variables (all of them int) and set them all to 0. I then do some operations (not in a loop). After each operation, I need to reset the local variables' values to 0. Right now, I am manually setting all the variables to 0 after each operation. Is there a better way to reset them all to 0 each time, maybe by calling some function rather than maunally doing it?
DECLARE @int1 int
DECLARE @int2 int
DECLARE @int3 int
DECLARE @int4 int
DECLARE @int5 int
SET @int1 = 0
SET @int2 = 0
SET @int3 = 0
SET @int4 = 0
SET @int4 = 0
-- Operation 1
SELECT * FROM Orders
-- Reset values (Number of times the reset code written: 1)
SET @int1 = 0
SET @int2 = 0
SET @int3 = 0
SET @int4 = 0
SET @int4 = 0
-------------------- END OF OPERATION 1 and RESETTING VARIABLES ---------------
-- Operation 2
SELECT * FROM Lines
-- Reset values (Number of times the reset code written: 2)
SET @int1 = 0
SET @int2 = 0
SET @int3 = 0
SET @int4 = 0
SET @int4 = 0
-------------------- END OF OPERATION 2 and RESETTING VARIABLES ---------------
-- Operation 3
SELECT * FROM Customers
-- Reset values (Number of times the reset code written: 3)
SET @int1 = 0
SET @int2 = 0
SET @int3 = 0
SET @int4 = 0
SET @int4 = 0
-------------------- END OF OPERATION 3 and RESETTING VARIABLES ---------------
-- Operation 4
SELECT * FROM Address
-- Reset values (Number of times the reset code written: 4)
SET @int1 = 0
SET @int2 = 0
SET @int3 = 0
SET @int4 = 0
SET @int4 = 0
-------------------- END OF OPERATION 4 and RESETTING VARIABLES ---------------
-- Operation 5
SELECT * FROM Accounts
-- Reset values (Number of times the reset code written: 5)
SET @int1 = 0
SET @int2 = 0
SET @int3 = 0
SET @int4 = 0
SET @int4 = 0
-------------------- END OF OPERATION 5 and RESETTING VARIABLES ---------------
As it is clearly evident, resetting the local variables has been written 5 times (identified by "Number of times the reset code written: #"). Is there a better way to call a function which does the reset so that I only need to call a function, for example ResetVaraibles() that will have the code of resetting the local variables. Is it more clear now?