Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. SET ANSI_NULLS ON
  2. GO
  3. SET QUOTED_IDENTIFIER ON
  4. GO
  5.  
  6. ALTER PROCEDURE [dbo].[something]
  7. AS
  8. BEGIN
  9. SET NOCOUNT, XACT_ABORT ON;
  10.  
  11. SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
  12.  
  13. BEGIN TRY
  14. DECLARE @something INT
  15.  
  16. DECLARE ROW_RES CURSOR FOR
  17. SELECT something
  18. FROM something
  19.  
  20. OPEN ROW_RES
  21.  
  22. FETCH NEXT FROM ROW_RES INTO @something
  23.  
  24. WHILE (@@fetch_status = 0)
  25. BEGIN
  26. IF (@something > 0)
  27. BEGIN
  28. EXEC msdb.dbo.sp_send_dbmail
  29. @profile_name = 'myprofile',
  30. @from_address = 'do_not_reply@me.com',
  31. @recipients = 'me@me.com',
  32. @copy_recipients = 'ccme@me.com',
  33. @subject = @email_subject,
  34. @body = @email_body,
  35. @body_format = 'html'
  36. END
  37.  
  38. FETCH NEXT FROM ROW_RES INTO @something
  39. END
  40.  
  41. IF (@something = false )
  42. BEGIN
  43. UPDATE something
  44. SET something = (@something)
  45. WHERE something = @something
  46. END
  47. ELSE IF (@something = true)
  48. BEGIN
  49. INSERT INTO something (something)
  50. VALUES (@something)
  51. END
  52.  
  53. COMMIT TRAN
  54. END TRY
  55. BEGIN CATCH
  56. DECLARE @MESSAGE NVARCHAR(2000), @SEVERITY INT, @STATE INT
  57. --See if there is a hanging transaction
  58. IF @@TRANCOUNT > 0 ROLLBACK TRAN
  59. --Rethrow the error to the calling application
  60. SET @MESSAGE = ERROR_MESSAGE()
  61. SET @SEVERITY = ERROR_SEVERITY()
  62. SET @STATE = ERROR_STATE()
  63. RAISERROR(@MESSAGE, @SEVERITY, @STATE)
  64. END CATCH
  65.  
  66. SET NOCOUNT OFF;
  67. END
  68. CLOSE ROW_RES
  69. DEALLOCATE ROW_RES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement