[dbo].[DocumentManagementAddImageUpdateDoc]
CREATE PROCEDURE [dbo].[DocumentManagementAddImageUpdateDoc]
@inMssDocumentID int,
@inDocumentImage image
as
set nocount on
declare @theEnsureUniqueDocumentName bit = 1
declare @theOrderID int
declare @theDocumentName varchar(128)
declare @theImageID int
declare @theTempImageID int
declare @theErrorCode int
select
@theErrorCode = 2
if( @inMssDocumentID is null )
begin
set @theErrorCode = 3
end
else if( @inDocumentImage is null )
begin
set @theErrorCode = 4
end
else
begin
begin transaction
select
@theOrderID = MSSDocument.OrderFID,
@theDocumentName = MSSDocument.DocumentName,
@theImageID = MSSDocument.MSSDocumentImageFID
from MSSDocument
where MSSDocument.MSSDocumentID = @inMssDocumentID
if( @theImageID is not null )
begin
set @theErrorCode = 0
end
else if( @theDocumentName is not null )
begin
exec DocumentManagementInsertImage
@inOrderID = @theOrderID,
@inDocumentName = @theDocumentName,
@inDocumentImage = @inDocumentImage,
@outImageID = @theImageID output,
@outError = @theErrorCode output,
@inEnsureUniqueDocumentName = @theEnsureUniqueDocumentName
if( @theErrorCode = 0 )
begin
update MSSDocument set
MSSDocumentImageFID = @theImageID,
DocByteSize = datalength( @inDocumentImage )
where MSSDocument.MSSDocumentID = @inMssDocumentID
end
end
commit transaction
if( @theErrorCode = 1 )
begin
select
@theTempImageID = MSSDocument.MSSDocumentImageFID
from MSSDocument
where MSSDocument.MSSDocumentID = @inMssDocumentID
if( @theTempImageID is not null )
begin
select
@theErrorCode = 0,
@theImageID = @theTempImageID
end
end
end
select
ImageID = @theImageID,
ErrorCode = @theErrorCode
GO
GRANT EXECUTE ON [dbo].[DocumentManagementAddImageUpdateDoc] TO [MssExec]
GO