DECLARE @TaskName VARCHAR(50) = 'Suggested Count Export'
DECLARE @TaskDescription VARCHAR(100) = 'Suggested Count Export'
DECLARE @StoredProc VARCHAR(200)= 'qryExport_SuggestedCountUsageByStore'
DECLARE @Destination VARCHAR(255) = 'W:\MacromatiX\SiteData\JATesting\DataExports\SuggestedCount'
DECLARE @Zone VARCHAR(100) = 'Suggested Count Pilot'
DECLARE @EventId int = 0 --the value in Enums.EventDrivenType

IF NOT Exists(SELECT * FROM tbTaskname WHERE taskname = @TaskName)
BEGIN
	DECLARE @taskId INT
	DECLARE @xsltManagerId INT
	DECLARE @ExportZoneId INT
	INSERT INTO tbTaskName (TaskName, TaskDescription)
	VALUES (@TaskName, @TaskDescription)
	
	SET @taskId = Scope_Identity()
    SELECT @xsltManagerId = XsltManagerId FROM tbXsltManager WHERE StoredProcedure = @StoredProc
	SELECT @ExportZoneId = ZoneId FROM tbZone WHERE Zone = @Zone
	
	INSERT INTO tbTaskXsltExportDetail(TaskNameId, XsltManagerId)
	VALUES (@taskId, @xsltManagerId)
	
	
	INSERT INTO tbTaskXsltExport (TaskNameId, 
		[ExportDestination], 
		[ExportMissingDays], 
		[ExportCurrentDay], 
		[ArchiveAfterSent], 
		[RunOnQueueNumber], 
		[OverwriteExistingFiles], 
		[AutoStart], 
		[CreateEmptyFiles], 
		[Concatenation], 
		[Compression], 
		[ConfirmationSuccess], 
		[ConfirmationError], 
		[QueueMessageType], 
		[OverwriteQueueMessage])
	VALUES (@taskId, @Destination, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,  @EventId, 1)
	
	IF @ExportZoneId IS NOT NULL
	BEGIN
		INSERT INTO tbTaskXsltExportZone (TaskNameId, ZoneId)
		VALUES(@taskId, @ExportZoneId)
	END
END

GO
