• 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.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]