As soon as I formulated the question it became clear to me as well, so I already did the changes.
There is another much more tricky part in the logic. I was working on it yesterday at 12am (or today?) and may want another set of eyes to review...
>>Hi everybody,
>>
>>I'm working on an SP and there is some problem I'm trying to figure out the best way to solve.
>>
>>I'm writing PersonUpdate procedure right now.
>>
>>Depending on the Person Type this procedure tries to update several tables. I want to wrap the update in the transaction.
>>
>>All person types update People table with the same code.
>>
>>The way I coded it right now is this (pseudo-code)
>>
>>BEGIN TRY
>>
>>if type = one type
>> begin transaction
>> Update People
>> Update Other tables
>> commit transaction
>>else if different type
>> begin transaction
>> Update People
>> Update Other tables
>> commit transaction
>>etc.
>>END TRY
>>BEGIN TRY
>> General logic for failure, rollback transaction
>>end try
>>
>>
>>I'm wondering if there is a way to somehow move Update People logic to do it only once.
>>
>>Do you see a way to re-organize this procedure?
>>
>>Thanks again.
>
>
>
>BEGIN TRY
>begin transaction
> Update People
>
>if type = one type
> Update Other tables
>else if different type
> Update Other tables
>
>
>commit transaction
>etc.
>END TRY
>
>BEGIN CATCH
> General logic for failure, rollback transaction
>END CATCH
>
If it's not broken, fix it until it is.
My Blog