20090723
20090720
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SAVE_MS_GOODS]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SAVE_MS_GOODS]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


CREATE  PROCEDURE SAVE_MS_GOODS

	@CD_STORE 	    		VARCHAR(4),
	@CD_GOODS      		VARCHAR(4),
	@NM_GOODS		    	VARCHAR(50),
	@PR_SALE		    	INT,
	@CD_MENU	    		VARCHAR(14),
	@CD_MENU2			VARCHAR(14),
	@ALLOW_PERIOD		INTEGER,
	@ALLOW_TOTCNT		INTEGER,
	@ALLOW_DAYCNT		INTEGER,
	@DS_STATUS			INTEGER,
	@CD_SAWON_CHG   		VARCHAR(6),
	@I_SW           			CHAR(1)
AS
BEGIN

    IF @I_SW = 0
    BEGIN
		INSERT INTO  MS_GOODS (	CD_STORE, 	 
						CD_GOODS,     
						NM_GOODS, 	
						PR_SALE, 
						CD_MENU,	
						CD_MENU2,
						ALLOW_PERIOD,	 
						ALLOW_TOTCNT,
						ALLOW_DAYCNT,	
						CD_SAWON_CHG,     
						DS_STATUS
						)

                       		 	VALUES(	@CD_STORE,
						@CD_GOODS,     
						@NM_GOODS, 	
						@PR_SALE, 
						@CD_MENU,	
						@CD_MENU2,
						@ALLOW_PERIOD,	 
						@ALLOW_TOTCNT,
						@ALLOW_DAYCNT,	
						@CD_SAWON_CHG,     
						@DS_STATUS
						)			

    END
    ELSE 
    BEGIN
		UPDATE  MS_GOODS     SET 
						CD_GOODS		=@CD_GOODS,
						NM_GOODS		=@NM_GOODS,
						PR_SALE		=@PR_SALE,
						CD_MENU		=@CD_MENU,
						CD_MENU2		=@CD_MENU2,
						ALLOW_PERIOD	=@ALLOW_PERIOD,
						ALLOW_TOTCNT	=@ALLOW_TOTCNT,
						ALLOW_DAYCNT	=@ALLOW_DAYCNT,
						CD_SAWON_CHG	=@CD_SAWON_CHG,
						DS_STATUS		=@DS_STATUS,
						DT_CHANGE          	=GETDATE()
				WHERE    CD_STORE 		= @CD_STORE 
				      AND    CD_GOODS 		= @CD_GOODS


    END
    

	
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

update sl_sale_d set dc_member = dc_member * qty_sale
GO

