IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_docctgbase]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_docctgbase]
GO
CREATE procedure [dbo].[mps_save_docctgbase]
-- Add the parameters for the stored procedure here
@cmpid int,
@dc_id int,
@dc_code varchar(50),
@dc_type nvarchar(100),
@dc_share int,
@dc_security int,
@dc_powerlevel int,
@dc_querytime int,
@dc_viewscope int,
@dc_views int,
@dc_defaultquery int,
@dc_keys nvarchar(max)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- Insert statements for procedure here
UPDATE mps_docctg SET 
dc_code =  CASE WHEN @dc_code = '_none_' THEN dc_code ELSE @dc_code END,
dc_type =  CASE WHEN @dc_type = '_none_' THEN dc_type ELSE @dc_type END,
dc_share = CASE WHEN @dc_share = -999999999 THEN dc_share ELSE @dc_share END,
dc_viewscope = CASE WHEN @dc_viewscope = -999999999 THEN dc_viewscope ELSE @dc_viewscope END,
dc_views = CASE WHEN @dc_views = -999999999 THEN dc_views ELSE @dc_views END,
dc_security = CASE WHEN @dc_security = -999999999 THEN dc_security ELSE @dc_security END,
dc_powerlevel = CASE WHEN @dc_powerlevel = -999999999 THEN dc_powerlevel ELSE @dc_powerlevel END,
dc_querytime = CASE WHEN @dc_querytime = -999999999 THEN dc_querytime ELSE @dc_querytime END,
dc_defaultquery = CASE WHEN @dc_defaultquery = -999999999 THEN dc_defaultquery ELSE @dc_defaultquery END,
dc_keys = CASE WHEN @dc_keys = '_none_' THEN dc_keys ELSE @dc_keys END ,
dc_changed = 0 
WHERE dc_id = @dc_id AND dc_cmpid = @cmpid
END