Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. USE [WFMSDB]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[restUpdateWPMetadata] Script Date: 2/27/2020 2:26:21 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROCEDURE [dbo].[restUpdateWPMetadata]
  9. @strlData nvarchar(MAX)
  10.  
  11.  
  12. AS
  13. SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  14. SET NOCOUNT ON
  15.  
  16. -- ============ Declarations section ============
  17. -- Standard variables
  18. DECLARE @l_vchProcname varchar(35)
  19. DECLARE @l_vchParmname varchar(35)
  20. DECLARE @l_vchTablename varchar(255)
  21. DECLARE @l_vchMessage varchar(255)
  22. DECLARE @l_intError int
  23. DECLARE @l_intRowcount int
  24. DECLARE @l_intRtrncode int
  25. DECLARE @l_intErrnum int
  26. DECLARE @l_intSqlstatus int
  27. DECLARE @l_intSuccess int
  28. DECLARE @l_intFail int
  29. DECLARE @l_intNTFND int
  30. DECLARE @l_dtmCurrentDate datetime
  31. DECLARE @l_vchServerName varchar(255)
  32.  
  33. -------------------------------------------------
  34. -- Local variables
  35.  
  36. -------------------------------------------------
  37. -- Initialize standard variables
  38. SELECT @l_vchProcname = OBJECT_NAME(@@procid)
  39. SELECT @l_intError = 0, @l_intRtrncode = 0, @l_intRowcount = 0, @l_intSqlstatus = 0
  40. SELECT @l_intSuccess = 0, @l_intFail = -1, @l_intNTFND = 100
  41. SELECT @l_dtmCurrentDate = GETDATE()
  42. SELECT @l_vchServerName = @@SERVERNAME
  43.  
  44. -------------------------------------------------
  45. BEGIN TRY
  46. -------------------------------------------------
  47.  
  48. BEGIN TRAN
  49. ------------------------------
  50. --main Part
  51. DECLARE @xmlData XML
  52. SET @xmlData = CONVERT(XML, @strlData)
  53.  
  54. -- Get input data
  55. SELECT
  56. x.value('Platform_ID[1]', 'smallint') AS Platform_ID,
  57. x.value('Platform_Name[1]', 'varchar(50)') AS Platform_Name,
  58. x.value('Property_Name[1]', 'varchar(50)') AS Property_Name,
  59. x.value('Property_Value[1]', 'varchar(50)') AS Property_Value,
  60. x.value('Property_Type[1]', 'smallint') AS Property_Type
  61. INTO #newMetaProps
  62. FROM @xmlData.nodes('//metaprops') XmlData(x)
  63.  
  64.  
  65. -- Delete old metadata for platform
  66. DELETE
  67. pmp
  68. FROM
  69. PLATFORM_META_PROPS pmp
  70. WHERE pmp.Platform_ID = (SELECT TOP(1)
  71. Platform_ID
  72. FROM #newMetaProps)
  73.  
  74.  
  75. -- Insert new metadata for platform
  76. INSERT INTO PLATFORM_META_PROPS
  77. (
  78. Platform_ID,
  79. Platform_Name,
  80. Property_Name,
  81. Property_Value,
  82. Property_Type
  83. )
  84. SELECT
  85. t.Platform_ID,
  86. t.Platform_Name,
  87. t.Property_Name,
  88. t.Property_Value,
  89. t.Property_Type
  90. FROM
  91. #newMetaProps t
  92.  
  93.  
  94. -- Drop temporary table
  95. DROP TABLE #newMetaProps
  96.  
  97. SET @l_intRtrncode = 200
  98.  
  99. COMMIT TRAN
  100.  
  101. -------------------------------------------------
  102. END TRY
  103.  
  104. BEGIN CATCH
  105. SELECT
  106. @l_intRtrncode = @l_intFail,
  107. @l_intErrnum = ERROR_NUMBER(),
  108. @l_vchMessage = ERROR_MESSAGE()
  109.  
  110. SELECT
  111. @l_vchMessage = @l_vchProcname + ' error ' + CONVERT( varchar(9), @l_intErrnum ) + ': ' + @l_vchMessage
  112.  
  113. IF @@TRANCOUNT > 0 -- Uncompleted transaction in the database
  114. ROLLBACK TRAN
  115. INSERT INTO _log (StatusDescr)
  116. VALUES(@l_vchMessage)
  117. RAISERROR (@l_vchMessage,16,1)
  118.  
  119. END CATCH
  120.  
  121. RETURN @l_intRtrncode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement