>Why did that work? What is the relationship between the FETCH and the BEGIN?
Because there is no such strunctures like
IF
ENDIF
DO WHILE
ENDDO
which closes the blocks you need to put ALL statements you need to be executed in this block in
BEGIN
END
In VFP we have:
IF SomeCondition
do line 1
do line 2
...
do line N
ENDIF
And VFP knows that all these lines should be executed IF SomeCondition is satisfied.
In TSQL (because of no ENDIF statement):
IF SomeCondition
BEGIN
do line 1
do line 2
...
do line N
END
and then SQL Server knows that ALL these lines should be executed IF SomeCondition is satisfied.
but if you have one code BEFORE BEGIN than that code will be executed IF SomeCondition is satisfied and the rest of code will be executed no matter what you have.
And that is valid not only for IF, but for WHILE also.
Here one example:
DECLARE @test int
SET @Test = 0
IF @Test = 1
print 'Line 1'
print 'Line 2'
print 'Line 3'
print 'Line 4'
print 'Line 5'
print 'Line 6'
Result:
Line 2
Line 3
Line 4
Line 5
Line 6
But:
DECLARE @test int
SET @Test = 0
IF @Test = 1
BEGIN
print 'Line 1'
print 'Line 2'
print 'Line 3'
print 'Line 4'
print 'Line 5'
print 'Line 6'
END
Result:
none, not a single print.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.