[dbo].[GetDocumentByteSize]
create procedure [dbo].[GetDocumentByteSize]
@inMSSDocumentImageID int,
@outDocByteSize int output
as
set nocount on;
set xact_abort on
begin try
declare @theExternalDBImageID int
declare @theExternalDBImageDB sysname
select
@theExternalDBImageID = MSSDocumentImage.ExtImageFID,
@theExternalDBImageDB = isnull( MSSDocumentImageDB.DatabaseName, dbo.GetDocDbName() ),
@outDocByteSize = datalength( MSSDocumentImage.DocumentImage )
from MSSDocumentImage
left outer join MSSDocumentImageDB on MSSDocumentImageDB.MSSDocumentImageDBID = MSSDocumentImage.MSSDocumentImageDBFID
where
MSSDocumentImage.MSSDocumentImageID = @inMSSDocumentImageID and
( MSSDocumentImageDB.MSSDocumentImageDBID is null or MSSDocumentImageDB.IsRemoved = 0 )
if(
@outDocByteSize is null and
@theExternalDBImageID is not null and
exists ( select top 1 1 from sys.databases where name = @theExternalDBImageDB ) )
begin
declare @theDynamicSql nvarchar(500)
set @theDynamicSql = N'set @outDocByteSize = null
select @outDocByteSize = datalength( DocumentImage.DocumentImage )
from ' + @theExternalDBImageDB + N'..DocumentImage
where DocumentImage.DocumentImageID = @inImageID'
exec sp_executesql @theDynamicSql, N'@inImageID int, @outDocByteSize int output',
@theExternalDBImageID,
@outDocByteSize output
end
end try
begin catch
set @outDocByteSize = null
end catch
GO
GRANT EXECUTE ON [dbo].[GetDocumentByteSize] TO [MssExec]
GO