IF EXISTS (SELECT 1 FROM SYS.TABLES WHERE NAME='LD0P0OLDDOCUMENTQUEUE')
BEGIN
DROP TABLE LD0P0OLDDOCUMENTQUEUE
END
;
IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0V0OLDDOCUMENTQUEUE')
BEGIN
DROP VIEW LD0V0OLDDOCUMENTQUEUE
END
;
CREATE TABLE LD0P0OLDDOCUMENTQUEUE
(
    ID INT IDENTITY(1,1) NOT NULL,  
    PNR VARCHAR(12) NOT NULL,       
    FILENAME VARCHAR(100) NOT NULL, 
    ARCHSTATE INT NOT NULL,         
    ARCHDAT DATETIME NOT NULL,      
    ARCHIVECOUNT INT NULL,          
    ERRORMESSAGE VARCHAR(250) NULL,
	CONSTRAINT 	LD0P0OLDDOCUMENTQUEUE_PKID PRIMARY KEY (ID)
)
;
CREATE VIEW LD0V0OLDDOCUMENTQUEUE AS 
	SELECT * FROM LD0P0OLDDOCUMENTQUEUE
;