I am confused, the last count comes from a table.
The first variable is zero and then it adds one to it.
But the first select the value of first is 2 and i am confused, this is only a simple loop.
Thoughts ?
SELECT @last = COUNT(*) FROM SOMETABLE
--Testing set to 2
select @last = 2
SELECT @first = 0
WHILE(@first < @last)
PRINT 'here'
BEGIN
BEGIN TRANSACTION
SET @first += 1
BEGIN TRY
SELECT @SOMDATE = DATA1
FROM SOMETABLE WHERE EXTRACT_KEY_ID = '1' --@first
print @first
---This is not one it is two
BEGIN
INSERT INTO SOME TABLE
END
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0
ROLLBACK TRANSACTION
Do something
END CATCH
END