First of all, your current code in your cursor has some bugs:
-you never set @tam-2 variable,
-if no records found in SGT table, @tam-2 will be NULL and your IF with "<>" is not going to work
-END for the BEGIN for the first IF is out of place. It should not be after FETCH NEXT, but before the second IF
The second, and most important: you don't need a cursor at all to do what you're doing.