ALTER PROCEDURE WZ_CONNECT_MEMB
@memb___id varchar(10),
@ServerName  varchar(20),
@IP varchar(15)	
 AS
Begin	
set nocount on
	Declare  @find_id varchar(10)
	Declare  @ConnectStat tinyint
	Declare @day_chenh int
	
	SET @day_chenh = 0			-- So ngay chenh giua thoi gian may tinh voi thoi gian thuc
	
	Set @find_id = 'NOT'
	Set @ConnectStat = 1		--    1 = Connect , 0 = Disconnect
	
	select @find_id = S.memb___id from MEMB_STAT S INNER JOIN MEMB_INFO I ON S.memb___id collate DATABASE_DEFAULT = I.memb___id collate DATABASE_DEFAULT
	       where I.memb___id = @memb___id

	if( @find_id = 'NOT' )
	begin		
		insert into MEMB_STAT (memb___id,ConnectStat,ServerName,IP,ConnectTM)
		values(@memb___id,  @ConnectStat, @ServerName, @IP, DATEADD(d,@day_chenh,getdate()))
	end
	else		
		update MEMB_STAT set ConnectStat = @ConnectStat,
					 ServerName = @ServerName,IP = @IP,
					 ConnectTM = DATEADD(d,@day_chenh,getdate())
       	 where memb___id = @memb___id
end