IF (select COUNT(*) from #files WHERE FILENAME like 'Access is denied%') >0
BEGIN
raiserror('Error in Filecheck, Access is Denied! Killing the SPID now.' ,22,127) with log
END
ELSE
BEGIN
CREATE TABLE #object (object_id INT)
-- Populate the table with the distinct path names
INSERT #object (object_id)
SELECT object_id
FROM object
WHERE Not exists (select * from #files where REVERSE(SUBSTRING(SUBSTRING(REVERSE(object_file), 2, 255), 1, PATINDEX('%\%', REVERSE(object_file)) -2)) = filename )
AND arch_id IS NULL
UPDATE object
SET filechk = 0
--where filechk = 0
from object o, #object t
Where o.object_id = t.object_id
END
DECLARE @i_missing_files INT -- Number of missing files
DECLARE @i_err_lvl INT -- Severity level that we shall pass to RAISERROR
SELECT @i_missing_files = (SELECT COUNT(*) FROM object WHERE filechk = 0)
--Set severity level (<15 is info, 15 is warning, >15 is error)