Skip to content

Instantly share code, notes, and snippets.

@ESimmonds
Created August 22, 2013 14:59
Show Gist options
  • Select an option

  • Save ESimmonds/6308336 to your computer and use it in GitHub Desktop.

Select an option

Save ESimmonds/6308336 to your computer and use it in GitHub Desktop.
update a table with joins
Use Curacao
GO
SET XACT_ABORT ON
BEGIN TRY
BEGIN TRANSACTION;
DECLARE @recordNumber int = 136512, @type nvarchar(10) = 'Intern'
Update r
Set Type = @type
from RecordHolder r
inner join LegacyServiceRegistration l on l.Person_id = r.PersonInfo_id
where l.RecordNumber = @recordNumber
--COMMIT TRANSACTION
ROLLBACK TRANSACTION
END TRY
BEGIN CATCH
PRINT
N'The transaction is in an uncommittable state.' +
'Rolling back transaction.'
PRINT ERROR_NUMBER() + ' ' + ERROR_MESSAGE()
ROLLBACK TRANSACTION
END CATCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment