Please refer below scenario for same.
CREATE Table #Temp
(
Ind INT IDENTITY(1,1),
EmpID VARCHAR(50),
DOJ DATE,
SAL INT,
Nationality VARCHAR(50)
)
DECLARE @MinIdt INT, @MaxIdt INT
INSERT INTO #Temp SELECT
EMPID,DOJ,SAL FROM EMP --------- FOR SOME
CONDITION
DECLARE
@MinIdt INT
DECLARE
@MaxIdt INT
SELECT @MinIdt = MIN(IDT), @MaxIdt = MAX(IDT) FROM #Temp
WHILE
@MinIdt <= @MaxIdt
BEGIN
-- Check 1st Condition
--IF EXISTS
--CHECK 2nd Condition
-- IF True 3rd
Condition
--THEN
-- check
Nationality for lets say Indian 4th Condition
--Update
Emp table with condition
--
Update one more log table
--else
--check
for lets say NRI
--Update Emp table
with condition
-- Update one more
log table
END
chetan tembhrePosted Apr 24, 2013, 2:35 AM
M ePosted Apr 23, 2013, 11:48 AM
I see that you have to update some tables , maybe you can use the MERGE statement , and also use CTEs.
Also i think that a core problem here is the SELECT that you're using to evaluate when the table should be updated.
We don't have the full query so for now we can only guess the goal that you want to achieve.
Regards.
Jignesh TrivediPosted Apr 23, 2013, 10:30 AM
hi,
you can use Common Table Expression(CTE) instead of cursor.
please refer
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/4aa613e1-9a47-413b-9a15-77fbce2a05fe
http://blogs.msdn.com/b/sqlprogrammability/archive/2008/03/18/increase-your-sql-server-performance-by-replacing-cursors-with-set-operations.aspx
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/238b4bba-8c54-41ad-8330-38520d48e089/
http://www.c-sharpcorner.com/UploadFile/ff2f08/common-table-expression-cte-in-sql-server/
hope this will help you.