IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_depart]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_depart]
GO

CREATE procedure [dbo].[mps_save_depart]
-- Add the parameters for the stored procedure here
@cmpid int,
@dp_id int,
@mybcid int,
--@dp_dpstdid int,
@dp_code varchar(100),
@dp_depart nvarchar(100),
@dp_salebudget int,
@dp_feebudget int,
@dp_mcuid1 int,
@dp_mcuid2 int,
@dp_mcuid3 int,
@dp_mcuid4 int,
@dp_mcuid5 int,
@dp_mcuid6 int,
@dp_mcuid7 int,
@dp_mcuid8 int,
@dp_mcuid9 int,
@dp_mcuid10 int,
@dp_manager1 nvarchar(50),
@dp_manager2 nvarchar(50),
@dp_manager3 nvarchar(50),
@dp_manager4 nvarchar(50),
@dp_manager5 nvarchar(50),
@dp_manager6 nvarchar(50),
@dp_manager7 nvarchar(50),
@dp_manager8 nvarchar(50),
@dp_manager9 nvarchar(50),
@dp_manager10 nvarchar(50)
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_depart SET 
dp_code =  CASE WHEN @dp_code = '_none_' THEN dp_code ELSE @dp_code END,
dp_depart =  CASE WHEN @dp_depart = '_none_' THEN dp_depart ELSE @dp_depart END,
dp_salebudget = CASE WHEN @dp_salebudget = -999999999 THEN dp_salebudget ELSE @dp_salebudget END,
dp_feebudget =  CASE WHEN @dp_feebudget = -999999999 THEN dp_feebudget ELSE @dp_feebudget END,
dp_mcuid1 = CASE WHEN @dp_mcuid1 = -999999999 THEN dp_mcuid1 ELSE @dp_mcuid1 END,
dp_mcuid2 = CASE WHEN @dp_mcuid2 = -999999999 THEN dp_mcuid2 ELSE @dp_mcuid2 END,
dp_mcuid3 = CASE WHEN @dp_mcuid3 = -999999999 THEN dp_mcuid3 ELSE @dp_mcuid3 END,
dp_mcuid4 = CASE WHEN @dp_mcuid4 = -999999999 THEN dp_mcuid4 ELSE @dp_mcuid4 END,
dp_mcuid5 = CASE WHEN @dp_mcuid5 = -999999999 THEN dp_mcuid5 ELSE @dp_mcuid5 END,
dp_mcuid6 = CASE WHEN @dp_mcuid6 = -999999999 THEN dp_mcuid6 ELSE @dp_mcuid6 END,
dp_mcuid7 = CASE WHEN @dp_mcuid7 = -999999999 THEN dp_mcuid7 ELSE @dp_mcuid7 END,
dp_mcuid8 = CASE WHEN @dp_mcuid8 = -999999999 THEN dp_mcuid8 ELSE @dp_mcuid8 END,
dp_mcuid9 = CASE WHEN @dp_mcuid9 = -999999999 THEN dp_mcuid9 ELSE @dp_mcuid9 END,
dp_mcuid10 = CASE WHEN @dp_mcuid10 = -999999999 THEN dp_mcuid10 ELSE @dp_mcuid10 END,
dp_manager1 =  CASE WHEN @dp_manager1 = '_none_' THEN dp_manager1 ELSE @dp_manager1 END,
dp_manager2 =  CASE WHEN @dp_manager2 = '_none_' THEN dp_manager2 ELSE @dp_manager2 END,
dp_manager3 =  CASE WHEN @dp_manager3 = '_none_' THEN dp_manager3 ELSE @dp_manager3 END,
dp_manager4 =  CASE WHEN @dp_manager4 = '_none_' THEN dp_manager4 ELSE @dp_manager4 END,
dp_manager5 =  CASE WHEN @dp_manager5 = '_none_' THEN dp_manager5 ELSE @dp_manager5 END,
dp_manager6 =  CASE WHEN @dp_manager6 = '_none_' THEN dp_manager6 ELSE @dp_manager6 END,
dp_manager7 =  CASE WHEN @dp_manager7 = '_none_' THEN dp_manager7 ELSE @dp_manager7 END,
dp_manager8 =  CASE WHEN @dp_manager8 = '_none_' THEN dp_manager8 ELSE @dp_manager8 END,
dp_manager9 =  CASE WHEN @dp_manager9 = '_none_' THEN dp_manager9 ELSE @dp_manager9 END,
dp_manager10 =  CASE WHEN @dp_manager10 = '_none_' THEN dp_manager10 ELSE @dp_manager10 END
WHERE dp_id = @dp_id AND dp_bcid = @mybcid AND dp_cmpid = @cmpid

SELECT 1 NONE WHERE 0=1
EXEC mps_update_departinfo @cmpid,@mybcid
    set nocount off
END