SELECt * FROM TBFOLDERIMPORT_PROFILE
CREATE TABLE TBFOLDERIMPORT_PROFILE
(
	GUID			INTEGER	IDENTITY(1,1),         				
	TITLE			VARCHAR(250)	NOT NULL,
	IMPORT_PATH		VARCHAR(900)	NOT NULL,
	REGEX_FILENAME	VARCHAR(250)	NOT NULL	DEFAULT '',
	LIMIT_FILECOUNT	TINYINT			NOT NULL	DEFAULT 0,
	DOCTYPE_ID		INTEGER			NOT NULL,
	ARCHIVE_PATH	VARCHAR(900)	NOT NULL	DEFAULT '',
	COMMENT			VARCHAR(200),
	ADDED_WHO		VARCHAR(50)		DEFAULT 'DEFAULT'	NOT NULL,
	ADDED_WHEN		DATETIME 		DEFAULT GETDATE(),
	CHANGED_WHO		VARCHAR(50),
	CHANGED_WHEN	DATETIME,
	CONSTRAINT		PK_TBFOLDERIMPORT_PROFILE	PRIMARY KEY (GUID),
	CONSTRAINT		UC_TBFOLDERIMPORT_PROFILE UNIQUE (IMPORT_PATH),
)
GO

CREATE TRIGGER [dbo].[TBFOLDERIMPORT_PROFILE_AFT_UPD] ON [dbo].[TBFOLDERIMPORT_PROFILE]
FOR UPDATE
AS
BEGIN 
	UPDATE TBFOLDERIMPORT_PROFILE SET CHANGED_WHEN = GETDATE() FROM INSERTED WHERE TBFOLDERIMPORT_PROFILE.GUID = INSERTED.GUID
END		
GO

ALTER PROCEDURE PRIDBFOLDERIMPORT_PROFILE (	@TITLE VARCHAR(250),
												@IMPORT_PATH VARCHAR(900),
												@REGEX_FILENAME	VARCHAR(250),
												@LIMIT_FILECOUNT TINYINT,
												@DOCTYPE_ID	INTEGER,
												@ARCHIVE_PATH VARCHAR(900),
												@COMMENT VARCHAR(200),
												@WHO VARCHAR(50),
												@GUID INTEGER = 0)
AS
BEGIN
	IF @GUID = 0
		BEGIN
			INSERT INTO [dbo].[TBFOLDERIMPORT_PROFILE]
				   ([TITLE]
				   ,[IMPORT_PATH]
				   ,[REGEX_FILENAME]
				   ,[LIMIT_FILECOUNT]
				   ,[DOCTYPE_ID]
				   ,[ARCHIVE_PATH]
				   ,[COMMENT]
				   ,[ADDED_WHO]
				   )
			 VALUES
				   (@TITLE
				   ,@IMPORT_PATH
				   ,@REGEX_FILENAME
				   ,@LIMIT_FILECOUNT
				   ,@DOCTYPE_ID
				   ,@ARCHIVE_PATH
				   ,@COMMENT
				   ,@WHO);
			SELECT @GUID = GUID FROM TBFOLDERIMPORT_PROFILE WHERE IMPORT_PATH = @IMPORT_PATH;
		END
	ELSE
		BEGIN
			UPDATE [dbo].[TBFOLDERIMPORT_PROFILE]
			   SET [TITLE] = @TITLE
				  ,[IMPORT_PATH] = @IMPORT_PATH
				  ,[REGEX_FILENAME] = @REGEX_FILENAME
				  ,[LIMIT_FILECOUNT] = @LIMIT_FILECOUNT
				  ,[DOCTYPE_ID] = @DOCTYPE_ID
				  ,[ARCHIVE_PATH] = @ARCHIVE_PATH
				  ,[COMMENT] = @COMMENT
				  ,[CHANGED_WHO] = @WHO
			 WHERE GUID = @GUID
		END
	SELECT * FROM TBFOLDERIMPORT_PROFILE WHERE GUID = @GUID
END
GO
CREATE TABLE TBFOLDERIMPORT_STEP_ATTRIBUTE_SPLIT
(
	GUID			INTEGER	IDENTITY(1,1),         				
	PROFILE_ID		INTEGER	NOT NULL,
	PRAEFIX			VARCHAR(250)	NOT NULL DEFAULT '',
	SPLIT_CHARACTER	VARCHAR(10)	NOT NULL,
	SPLIT_POS		TINYINT		NOT NULL,
	SUFFIX			VARCHAR(250)	NOT NULL DEFAULT '',
	ATTRIBUTE		VARCHAR(900)	NOT NULL,
	COMMENT			VARCHAR(200),
	ADDED_WHO		VARCHAR(50)		DEFAULT 'DEFAULT'	NOT NULL,
	ADDED_WHEN		DATETIME 		DEFAULT GETDATE(),
	CHANGED_WHO		VARCHAR(50),
	CHANGED_WHEN	DATETIME,
	CONSTRAINT		PK_TBFOLDERIMPORT_STEP_ATTRIBUTE_SPLIT	PRIMARY KEY (GUID),
	CONSTRAINT		UC_TBFOLDERIMPORT_STEP_ATTRIBUTE_SPLIT UNIQUE (PROFILE_ID,ATTRIBUTE),
	CONSTRAINT		FK_TBFOLDERIMPORT_STEP_ATTRIBUTE_SPLIT	FOREIGN KEY(PROFILE_ID)	REFERENCES TBFOLDERIMPORT_PROFILE(GUID)
)
GO