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

create proc [dbo].[update_doc_showinfo]
@docid bigint,
@branchid int,
@userdpid int,
@useruid int,
@cmpid int,
@value int
as 
begin
set nocount on
declare @userlike bigint, @docvid bigint;
select @userlike = docv_like,@docvid = docv_id from mps_document_view 
where docv_docid=@docid and docv_cuid = @useruid and docv_bcid = @branchid and docv_dpid = @userdpid
if @userlike!=1 and @userlike !=2 and @userlike !=-1
begin
update mps_document set doc_like += @value where doc_id=@docid and doc_cmpid=@cmpid
if @value = 0
begin
update mps_document_view set docv_like = -1
where docv_id=@docvid
end
else
begin
update mps_document_view set docv_like = @value
where docv_id=@docvid
end
end
set nocount off
end