sgmunson - Thursday, July 12, 2018 12:06 PM
Yeah, -2 can get you if you just code "@@FETCH_STATUS <> 0". By default, "If FORWARD_ONLY is specified without the STATIC, KEYSET, or DYNAMIC keywords, the cursor operates as a DYNAMIC cursor." And I've seen some cases where that caused cursors to exit well before the entire set was processed.
So one needs to either explicitly force the cursor to not be able to get a -2 (rather tricky for many developers to be sure of anyway) or code an explicit check for it. I just always code for it, then I never get unexpectedly burned even if the cursor reverts to dynamic from some changes to it.
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.