DROP PROCEDURE IF EXISTS dev.uspAddOrUpdateExtendedProperty
GO

CREATE PROCEDURE dev.uspAddOrUpdateExtendedProperty
   @name nvarchar(255)
  ,@value nvarchar(2000)
  ,@level0type nvarchar(255)
  ,@level0name nvarchar(255)
  ,@level1type nvarchar(255) = NULL
  ,@level1name nvarchar(255) = NULL
  ,@level2type nvarchar(255) = NULL
  ,@level2name nvarchar(255) = NULL
AS
BEGIN
  IF EXISTS (SELECT 1 FROM fn_listextendedproperty (@name,  @level0type, @level0name, @level1type, @level1name, @level2type, @level2name)) BEGIN
    EXECUTE sp_updateextendedproperty 
       @name, @value
      ,@level0type, @level0name
      ,@level1type, @level1name
      ,@level2type, @level2name
  END
  ELSE BEGIN
    EXECUTE sp_addextendedproperty
       @name, @value
      ,@level0type, @level0name
      ,@level1type, @level1name
      ,@level2type, @level2name
  END
END


