IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_saleprds_details]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_saleprds_details]
GO
 
CREATE proc [dbo].[mps_save_saleprds_details]
@sp_id int,
@cmpid int,
@useruid int,
@branchid int,
@userdpid int,
@sp_type nvarchar(100),
@sp_prdid bigint,
@sp_category1 nvarchar(50),
@sp_category2 nvarchar(50),
@sp_category3 nvarchar(50),
@sp_code nvarchar(50),
@sp_caption nvarchar(100),
@sp_brand nvarchar(50),
@sp_model nvarchar(100),
@sp_spec nvarchar(100),
@sp_unit nvarchar(20),
@sp_pack nvarchar(100),
@sp_ext nvarchar(100),
@sp_amount int,
@sp_price decimal(18 ,2),
@sp_score int,
@sp_key varchar(30),
@sp_click int,
@sp_sale int,
@sp_limited int,
@sp_price0 decimal(18,2),
@sp_additional nvarchar(500),
@sp_special nvarchar(500),
@sp_status nvarchar(20),
@sp_use int,
@sp_order int,
@sp_begin datetime,
@sp_end datetime,
@sp_tag int,
@sp_pcid int,
@sp_icon varchar(200),
@sp_text nvarchar(max)
as
begin
set nocount on

update mps_saleprds set
sp_prdid = case when @sp_prdid = -999999999 then sp_prdid else @sp_prdid end,
sp_category1 = case when @sp_category1 = '_none_' then sp_category1 else @sp_category1 end,
sp_category2 = case when @sp_category2 = '_none_' then sp_category2 else @sp_category2 end,
sp_category3 = case when @sp_category3 = '_none_' then sp_category3 else @sp_category3 end,
sp_code = case when @sp_code = '_none_' then sp_code else @sp_code end,
sp_caption = case when @sp_caption = '_none_' then sp_caption else @sp_caption end,
sp_model = case when @sp_model = '_none_' then sp_model else @sp_model end,
sp_brand = case when @sp_brand = '_none_' then sp_brand else @sp_brand end,
sp_spec = case when @sp_spec = '_none_' then sp_spec else @sp_spec end,
sp_unit = case when @sp_unit = '_none_' then sp_unit else @sp_unit end,
sp_pack = case when @sp_pack = '_none_' then sp_pack else @sp_pack end,
sp_ext = case when @sp_ext = '_none_' then sp_ext else @sp_ext end,
sp_amount = case when @sp_amount = -999999999 then sp_amount else @sp_amount end,
sp_price = case when @sp_price = -999999999 then sp_price else @sp_price end,
sp_score = case when @sp_score = -999999999 then sp_score else @sp_score end,
sp_key = case when @sp_key = '_none_' then sp_key else @sp_key end,
sp_click = case when @sp_click = -999999999 then sp_click else @sp_click end,
sp_sale = case when @sp_sale = -999999999 then sp_sale else @sp_sale end,
sp_limited = case when @sp_limited = -999999999 then sp_limited else @sp_limited end,
sp_price0 = case when @sp_price0 = -999999999 then sp_price0 else @sp_price0 end,
sp_additional = case when @sp_additional = '_none_' then sp_additional else @sp_additional end,
sp_special = case when @sp_special = '_none_' then sp_special else @sp_special end,
sp_status = case when @sp_status = '_none_' then sp_status else @sp_status end,
sp_use = case when @sp_use = -999999999 then sp_use else @sp_use end,
sp_order = case when @sp_order = -999999999 then sp_order else @sp_order end,
sp_begin = case when @sp_begin <= '1970-1-1' then sp_begin else @sp_begin end,
sp_end = case when @sp_end <= '1970-1-1' then sp_end else @sp_end end,
sp_tag = case when @sp_tag = -999999999 then sp_tag else @sp_tag end,
sp_pcid = case when @sp_pcid = -999999999 then sp_pcid else @sp_pcid end,
sp_icon = case when @sp_icon = '_none_' then sp_icon else @sp_icon end,
sp_text = case when @sp_text = '_none_' then sp_text else @sp_text end
where sp_id = @sp_id and sp_cmpid = @cmpid

set nocount off
end