/*-------------------------------------------------------------------------
 * Stored procedure to fetch the list of files in the delete pending list
 *------------------------------------------------------------------------*/


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MSP_WEB_SP_VWSVC_FetchDeletePendingList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[MSP_WEB_SP_VWSVC_FetchDeletePendingList]
GO


CREATE PROCEDURE dbo.MSP_WEB_SP_VWSVC_FetchDeletePendingList
AS
SELECT * FROM MSP_VIEW_SERVICE_FILE_DELETE_PENDING
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_VWSVC_FetchDeletePendingList TO MSProjectServerRole
GO


/*-------------------------------------------------------------------------
 * Stored procedure to remove files from the delete pending list
 *------------------------------------------------------------------------*/


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MSP_WEB_SP_VWSVC_RemoveFilesFromDeletePendingList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[MSP_WEB_SP_VWSVC_RemoveFilesFromDeletePendingList]
GO

CREATE PROCEDURE dbo.MSP_WEB_SP_VWSVC_RemoveFilesFromDeletePendingList
	@FileList ntext
AS

set nocount on
begin transaction RemoveDeletedFiles

select TokenVal  into #FilesToDelete from dbo.MSP_WEB_FN_ConvertStringListToTable(@FileList) 

declare @Filename nvarchar(1024)
declare csrFileList cursor for select TokenVal from #FilesToDelete
open csrFileList

fetch next from csrFileList into @Filename
while @@fetch_status = 0
begin
	delete from MSP_VIEW_SERVICE_FILE_DELETE_PENDING where cast(Filename as nvarchar(1024)) = @Filename
	fetch next from csrFileList into @Filename
end

close csrFileList
deallocate csrFileList
drop table #FilesToDelete

commit transaction RemoveDeletedFiles
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_VWSVC_RemoveFilesFromDeletePendingList TO MSProjectServerRole
GO


/*-------------------------------------------------------------------------
 * Stored procedure add files to delete pending list
 *------------------------------------------------------------------------*/

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MSP_WEB_SP_VWSVC_AddFilesToDeletePendingList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[MSP_WEB_SP_VWSVC_AddFilesToDeletePendingList]
GO

CREATE PROCEDURE dbo.MSP_WEB_SP_VWSVC_AddFilesToDeletePendingList
	@FileList ntext
AS
	Insert Into MSP_VIEW_SERVICE_FILE_DELETE_PENDING select TokenVal from dbo.MSP_WEB_FN_ConvertStringListToTable(@FileList)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_VWSVC_AddFilesToDeletePendingList TO MSProjectServerRole
GO


/*-------------------------------------------------------------------------
 * Stored procedure that is run to calculate which subset of rows should
 * be processed for this run of the views scheduling engine.
 *------------------------------------------------------------------------*/

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MSP_WEB_SP_VWSVC_FileDropUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[MSP_WEB_SP_VWSVC_FileDropUpdate]
GO


CREATE PROCEDURE dbo.MSP_WEB_SP_VWSVC_FileDropUpdate
	@argOrgId nvarchar(256),
	@argProjectId int,
	@argFilename ntext,
	@argDropTime datetime
AS

SET NOCOUNT ON
BEGIN TRANSACTION FileDrop

Declare @org_id nvarchar(50), @proj_id int, @latest_drop_time datetime, @drop_time datetime

/* Add new item to views drop table */
Insert Into MSP_VIEW_SERVICE_NEW_DROPS VALUES(@argOrgId, @argProjectId, @argFilename, @argDropTime)

/* Select the most recent drops for each org and project id. This leaves out the publish drop data as this would affect the aggregate */
SELECT Org, Project, MAX( DISTINCT DropTime) AS LatestDropTime INTO #Latest FROM MSP_VIEW_SERVICE_NEW_DROPS 
	GROUP BY Org, Project

/* Now build the temp table latest drops. This is the same as the temp table latest except that now it includes the publish drop data */
SELECT MSP_VIEW_SERVICE_NEW_DROPS.Org, MSP_VIEW_SERVICE_NEW_DROPS.Project, MSP_VIEW_SERVICE_NEW_DROPS.Filename, #Latest.LatestDropTime INTO #LatestDrops FROM MSP_VIEW_SERVICE_NEW_DROPS, #Latest 
	WHERE MSP_VIEW_SERVICE_NEW_DROPS.Org = #Latest.Org and
	      MSP_VIEW_SERVICE_NEW_DROPS.Project = #Latest.Project and
	      MSP_VIEW_SERVICE_NEW_DROPS.DropTime = #Latest.LatestDropTime

/* Build a list of publish drops that can be safely deleted since they are older than other drops for the same org and project */
SELECT MSP_VIEW_SERVICE_NEW_DROPS.* INTO #FilesToDelete FROM MSP_VIEW_SERVICE_NEW_DROPS, #LatestDrops 
	WHERE MSP_VIEW_SERVICE_NEW_DROPS.Org = #LatestDrops.Org AND
	      MSP_VIEW_SERVICE_NEW_DROPS.Project = #LatestDrops.Project AND
	      MSP_VIEW_SERVICE_NEW_DROPS.DropTime <> #LatestDrops.LatestDropTime


/* Delete rows from the newdrops table where they match the rows in the temp table filestodelete */
Declare del_csr cursor for
	select Org, Project, DropTime
	from MSP_VIEW_SERVICE_NEW_DROPS
Open del_csr
Fetch next from del_csr into @org_id, @proj_id, @drop_time
While @@fetch_status = 0
Begin
	if exists (select * from #FilesToDelete WHERE Org = @org_id and Project = @proj_id and DropTime = @drop_time)
	begin
		DELETE FROM MSP_VIEW_SERVICE_NEW_DROPS
			WHERE CURRENT OF del_csr
	end
	fetch next from del_csr into @org_id, @proj_id, @drop_time
End
Close del_csr
Deallocate del_csr 

/*
DELETE FROM MSP_VIEW_SERVICE_NEW_DROPS
            WHERE exists(select a.* from MSP_VIEW_SERVICE_NEW_DROPS as a 
                                    join #FilesToDelete as b 
                                    on a.Org = b.Org and a.Project = b.Project and a.DropTime = b.DropTime)*/

/* Add filenames of items to delete to the file delete pending table. */
INSERT INTO MSP_VIEW_SERVICE_FILE_DELETE_PENDING
	SELECT Filename FROM #FilesToDelete


/* Insert rows into the view status table for each publish that requires processing (preliminary) */
Insert Into MSP_VIEW_SERVICE_PUBLISH_STATUS Select Org, Project, [Filename], LatestDropTime, 1
	From #LatestDrops Where Not Exists (Select Org, Project 
					from MSP_VIEW_SERVICE_PUBLISH_STATUS
					where Org = #LatestDrops.Org and Project = #LatestDrops.Project)

           
/* 
 * Builds the topublishnow temp table. The contents of this temp table are returned to the caller of this stored procedure.
 * The caller is responsible for forwarding the publish drop data for each of these rows onward to the viewcreator object.
 */

SELECT #LatestDrops.* INTO #ToPublishNow FROM #LatestDrops, MSP_VIEW_SERVICE_PUBLISH_STATUS
	WHERE (#LatestDrops.Org = MSP_VIEW_SERVICE_PUBLISH_STATUS.Org AND 
               #LatestDrops.Project = MSP_VIEW_SERVICE_PUBLISH_STATUS.Project AND
               #LatestDrops.LatestDropTime >= MSP_VIEW_SERVICE_PUBLISH_STATUS.DropTime AND
	       MSP_VIEW_SERVICE_PUBLISH_STATUS.Status = 0) or 
	      (#LatestDrops.Org = MSP_VIEW_SERVICE_PUBLISH_STATUS.Org AND
               #LatestDrops.Project = MSP_VIEW_SERVICE_PUBLISH_STATUS.Project AND
               #LatestDrops.LatestDropTime < MSP_VIEW_SERVICE_PUBLISH_STATUS.DropTime) OR 
	      (#LatestDrops.Org = MSP_VIEW_SERVICE_PUBLISH_STATUS.Org AND 
               #LatestDrops.Project = MSP_VIEW_SERVICE_PUBLISH_STATUS.Project AND
               #LatestDrops.LatestDropTime = MSP_VIEW_SERVICE_PUBLISH_STATUS.DropTime AND
	       MSP_VIEW_SERVICE_PUBLISH_STATUS.Status = 1)

/* Add files that don't need processing to files to delete list */
SELECT #LatestDrops.* INTO #ProcessedFilesToDelete FROM #LatestDrops, MSP_VIEW_SERVICE_PUBLISH_STATUS
	WHERE  
	      (#LatestDrops.Org = MSP_VIEW_SERVICE_PUBLISH_STATUS.Org AND
               #LatestDrops.Project = MSP_VIEW_SERVICE_PUBLISH_STATUS.Project AND
               #LatestDrops.LatestDropTime < MSP_VIEW_SERVICE_PUBLISH_STATUS.DropTime)


/* Remove columns from new drops table that have been transferred to the view status table */
Declare del_csr2 cursor for
	select Org, Project, DropTime
	from MSP_VIEW_SERVICE_NEW_DROPS
Open del_csr2
Fetch next from del_csr2 into @org_id, @proj_id, @drop_time
While @@fetch_status = 0
Begin
	if exists (select * from #ToPublishNow WHERE Org = @org_id and Project = @proj_id and LatestDropTime = @drop_time)
	begin
		DELETE FROM MSP_VIEW_SERVICE_NEW_DROPS
			WHERE CURRENT OF del_csr2
	end
	fetch next from del_csr2 into @org_id, @proj_id, @drop_time
End
Close del_csr2
Deallocate del_csr2 

/*
DELETE FROM MSP_VIEW_SERVICE_NEW_DROPS
            WHERE exists(select a.* from MSP_VIEW_SERVICE_NEW_DROPS as a 
                                    join #ToPublishNow as b 
                                    on a.Org = b.Org and a.Project = b.Project and a.DropTime = b.LatestDropTime)*/


/* Set publish drop data and status bit to 1 where a new file requires publishing and an entry already exists in the view status table */
UPDATE MSP_VIEW_SERVICE_PUBLISH_STATUS 
	SET MSP_VIEW_SERVICE_PUBLISH_STATUS.Org = #LatestDrops.Org, MSP_VIEW_SERVICE_PUBLISH_STATUS.Project = #LatestDrops.Project, MSP_VIEW_SERVICE_PUBLISH_STATUS.Filename = #LatestDrops.Filename, MSP_VIEW_SERVICE_PUBLISH_STATUS.DropTime = #LatestDrops.LatestDropTime, MSP_VIEW_SERVICE_PUBLISH_STATUS.Status = 1
		FROM MSP_VIEW_SERVICE_PUBLISH_STATUS, #LatestDrops
			WHERE #LatestDrops.Org = MSP_VIEW_SERVICE_PUBLISH_STATUS.Org AND
		              #LatestDrops.Project = MSP_VIEW_SERVICE_PUBLISH_STATUS.Project AND
		              #LatestDrops.LatestDropTime > MSP_VIEW_SERVICE_PUBLISH_STATUS.DropTime AND
			      MSP_VIEW_SERVICE_PUBLISH_STATUS.Status = 0

/* Copy contents from processed files to delete temp table to the permanent files to delete list */
INSERT INTO MSP_VIEW_SERVICE_FILE_DELETE_PENDING
	SELECT Filename FROM #ProcessedFilesToDelete

/* Set the recordset to be returned from the sp */
SELECT * FROM #ToPublishNow 

DROP TABLE #Latest
DROP TABLE #LatestDrops
DROP TABLE #FilesToDelete
DROP TABLE #ProcessedFilesToDelete
DROP TABLE #ToPublishNow

COMMIT TRANSACTION FileDrop

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_VWSVC_FileDropUpdate TO MSProjectServerRole
GO


/*-------------------------------------------------------------------------
 * Stored procedure to update status table after views processing completes 
 * for an item in the table
 *------------------------------------------------------------------------*/

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MSP_WEB_SP_VWSVC_ViewProcessingCompleted]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[MSP_WEB_SP_VWSVC_ViewProcessingCompleted]
GO

CREATE PROCEDURE dbo.MSP_WEB_SP_VWSVC_ViewProcessingCompleted
	@Org nvarchar(256),
	@Project int
AS
	Update MSP_VIEW_SERVICE_PUBLISH_STATUS Set Status=0 Where Org = @Org and Project = @Project
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_VWSVC_ViewProcessingCompleted TO MSProjectServerRole
GO


/*-------------------------------------------------------------------------
 * Resets the scheduling tables when the views service starts
 *------------------------------------------------------------------------*/

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MSP_WEB_SP_VWSVC_ResetViewsScheduler]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[MSP_WEB_SP_VWSVC_ResetViewsScheduler]
GO

CREATE PROCEDURE dbo.MSP_WEB_SP_VWSVC_ResetViewsScheduler
AS
	Delete From MSP_VIEW_SERVICE_PUBLISH_STATUS
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_VWSVC_ResetViewsScheduler TO MSProjectServerRole
GO


/*-------------------------------------------------------------------------
 * Function to return a table variable from a comma-separated ID list
 *------------------------------------------------------------------------*/

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_FN_charindex_ex')
and xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.MSP_WEB_FN_charindex_ex
GO

create function dbo.MSP_WEB_FN_charindex_ex (@searchar nvarchar(1),@str ntext,@startloc int)
returns int
as
begin
   declare @curpos int, @strlen int, @charval nchar(1)
   set @strlen = datalength(@str)
   set @curpos = @startloc 
   while @curpos <= @strlen
   begin
	   if substring(@str,@curpos,1) = @searchar
		   break
	   set @curpos = @curpos + 1
   end
return @curpos
end
GO

GRANT EXECUTE ON dbo.MSP_WEB_FN_charindex_ex TO MSProjectServerRole
GO


/*-------------------------------------------------------------------------
 * Function to convert string list to table
 *------------------------------------------------------------------------*/

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_FN_ConvertStringListToTable')
and xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.MSP_WEB_FN_ConvertStringListToTable
GO
CREATE FUNCTION dbo.MSP_WEB_FN_ConvertStringListToTable(@ntext ntext)
RETURNS @TokenVals table (TokenVal nvarchar(1024))
AS
BEGIN
  declare @maxStrLen int
  declare @s nvarchar(4000)
  declare @textLen int
  declare @textPos int
  declare @nextTextDelim int
  declare @strLen int
  declare @strPos int
  declare @nextStrDelim int
  declare @val nvarchar(1024)

  set @maxStrLen = 4000

  set @textLen = datalength(@ntext) / 2 --2 bytes per char
  set @textPos = 1

  if (@textLen = 0) return

  -- Parse the text into strings of 8000 chars
  While (@textPos <= @textLen)
  Begin

     If ((@textLen - @textPos + 1) > @maxStrLen)
       begin
        set @s = substring(@ntext, @textPos, @maxStrLen)
        -- Search for the last delimiter within the string
        set @nextTextDelim = @maxStrLen - charindex(',', reverse(@s)) + 1

        -- cut the text to the last delimiter before the maxStrLen mark
        if (@nextTextDelim > 0)
           set @s = substring(@s, 1, @nextTextDelim - 1)
        else
           -- Rare case, happens only when the delimiter is exactly after the last char
           set @nextTextDelim = @maxStrLen + 1

        set @textPos = @textPos + @nextTextDelim
       end
     Else
       begin
        -- Last text block - convert it into string
        set @s = substring(@ntext, @textPos, @textLen - @textPos + 1)
        set @textPos = @textLen + 1
       end


     -- Parse the string
     set @strLen = len(@s)
     set @strPos = 0
     
     -- For each token, load it into the table
     While @strPos <= @strLen
     Begin
        -- get the next token
        set @nextStrDelim = charindex(',', @s, @strPos)
        if @nextStrDelim = 0
           set @nextStrDelim = @strLen + 1
     
        set @val = substring(@s, @strPos, @nextStrDelim - @strPos)
     
        -- load the table variable
        insert @TokenVals values (@val)
     
        -- increment to the next position, and handle the last token
        set @strPos = @nextStrDelim + 1
     End --string handling

  End --text handling

RETURN
END
GO


GRANT SELECT ON dbo.MSP_WEB_FN_ConvertStringListToTable TO MSProjectServerRole
GO


/* Query #50010 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable0
GO

/* Query #50011 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable1
GO

/* Query #50012 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable2
GO

/* Query #50020 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst0
GO

/* Query #50021 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst1
GO

/* Query #50022 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst2
GO

/* Query #50110 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable0
GO

/* Query #50111 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable1
GO

/* Query #50112 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable2
GO

/* Query #50120 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst0
GO

/* Query #50121 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst1
GO

/* Query #50122 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst2
GO

/* Query #50210 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable0
GO

/* Query #50211 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable1
GO

/* Query #50212 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable2
GO

/* Query #50220 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst0
GO

/* Query #50221 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst1
GO

/* Query #50222 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst2
GO

/* Query #50310 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable0
GO

/* Query #50311 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable1
GO

/* Query #50320 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst0
GO

/* Query #50321 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst1
GO

/* Query #50410 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTaskSplits_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskSplits_DeleteViewTable0
GO

/* Query #50420 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTaskSplits_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskSplits_SelectEmptyRst0
GO

/* Query #50510 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewPredecessors_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewPredecessors_DeleteViewTable0
GO

/* Query #50520 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewPredecessors_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewPredecessors_SelectEmptyRst0
GO

/* Query #50610 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewSuccessors_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewSuccessors_DeleteViewTable0
GO

/* Query #50620 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewSuccessors_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewSuccessors_SelectEmptyRst0
GO

/* Query #50710 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_DeleteViewTable0
GO

/* Query #50720 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_SelectEmptyRst0
GO

/* Query #50810 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_DeleteViewTable0
GO

/* Query #50820 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_SelectEmptyRst0
GO

/* Query #50850 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewCalendars_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendars_DeleteViewTable0
GO

/* Query #50860 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewCalendars_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendars_SelectEmptyRst0
GO

/* Query #50890 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewCalendarData_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarData_DeleteViewTable0
GO

/* Query #50900 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewCalendarData_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarData_SelectEmptyRst0
GO

/* Query #50930 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_DeleteViewTable0
GO

/* Query #50940 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_SelectEmptyRst0
GO

/* Query #51010 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable0
GO

/* Query #51011 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable1
GO

/* Query #51012 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable2
GO

/* Query #51020 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst0
GO

/* Query #51021 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst1')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst1
GO

/* Query #51022 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst2')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst2
GO

/* Query #51110 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_DeleteViewTable0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_DeleteViewTable0
GO

/* Query #51120 */
IF EXISTS (SELECT id FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_SelectEmptyRst0')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_SelectEmptyRst0
GO




/* Query #50010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_TASKS_STD where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable1
   @p0 INT
AS
delete from MSP_VIEW_PROJ_TASKS_CF  where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable1 TO MSProjectServerRole
GO



/* Query #50012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable2
   @p0 INT
AS
delete from MSP_VIEW_PROJ_TASKS_ENT where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTasks_DeleteViewTable2 TO MSProjectServerRole
GO



/* Query #50020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_TASKS_STD WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst1
AS
select * from MSP_VIEW_PROJ_TASKS_CF WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst1 TO MSProjectServerRole
GO



/* Query #50022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst2
AS
select * from MSP_VIEW_PROJ_TASKS_ENT WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTasks_SelectEmptyRst2 TO MSProjectServerRole
GO



/* Query #50110 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_RES_STD where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50111 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable1
   @p0 INT
AS
delete from MSP_VIEW_PROJ_RES_CF  where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable1 TO MSProjectServerRole
GO



/* Query #50112 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable2
   @p0 INT
AS
delete from MSP_VIEW_PROJ_RES_ENT where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewRes_DeleteViewTable2 TO MSProjectServerRole
GO



/* Query #50120 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_RES_STD WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50121 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst1
AS
select * from MSP_VIEW_PROJ_RES_CF WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst1 TO MSProjectServerRole
GO



/* Query #50122 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst2
AS
select * from MSP_VIEW_PROJ_RES_ENT WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewRes_SelectEmptyRst2 TO MSProjectServerRole
GO



/* Query #50210 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_ASSN_STD where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50211 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable1
   @p0 INT
AS
delete from MSP_VIEW_PROJ_ASSN_CF  where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable1 TO MSProjectServerRole
GO



/* Query #50212 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable2
   @p0 INT
AS
delete from MSP_VIEW_PROJ_ASSN_ENT where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssn_DeleteViewTable2 TO MSProjectServerRole
GO



/* Query #50220 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_ASSN_STD WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50221 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst1
AS
select * from MSP_VIEW_PROJ_ASSN_CF WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst1 TO MSProjectServerRole
GO



/* Query #50222 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst2
AS
select * from MSP_VIEW_PROJ_ASSN_ENT WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssn_SelectEmptyRst2 TO MSProjectServerRole
GO



/* Query #50310 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_PROJECTS_STD where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50311 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable1
   @p0 INT
AS
delete from MSP_VIEW_PROJ_PROJECTS_ENT where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewProject_DeleteViewTable1 TO MSProjectServerRole
GO



/* Query #50320 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_PROJECTS_STD WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50321 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst1
AS
select * from MSP_VIEW_PROJ_PROJECTS_ENT WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewProject_SelectEmptyRst1 TO MSProjectServerRole
GO



/* Query #50410 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskSplits_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_TASKSPLITS where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTaskSplits_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50420 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskSplits_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_TASKSPLITS WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTaskSplits_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50510 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewPredecessors_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_PRED where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewPredecessors_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50520 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewPredecessors_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_PRED WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewPredecessors_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50610 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewSuccessors_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_SUCC where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewSuccessors_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50620 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewSuccessors_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_SUCC WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewSuccessors_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50710 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_ASSN_TP_BY_DAY where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50720 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_ASSN_TP_BY_DAY WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewAssignmentTimephasedByDay_SelectEmptyRst0 TO MSProjectServerRole
GO


/* Query #50810 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_TASK_TP_BY_DAY where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50820 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_TASK_TP_BY_DAY WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewTaskTimephasedByDay_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50850 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendars_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_CAL where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewCalendars_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50860 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendars_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_CAL WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewCalendars_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50890 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarData_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_CAL_DATA where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewCalendarData_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50900 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarData_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_CAL_DATA WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewCalendarData_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #50930 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_PROJ_CAL_EXCEPTIONS where WPROJ_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #50940 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_SelectEmptyRst0
AS
select * from MSP_VIEW_PROJ_CAL_EXCEPTIONS WITH (READPAST) where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewCalendarExceptions_SelectEmptyRst0 TO MSProjectServerRole
GO

/* Query #51010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_RES_STD where ResourceUniqueID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #51011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable1
   @p0 INT
AS
delete from MSP_VIEW_RES_CF  where CF_ResourceUniqueID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable1 TO MSProjectServerRole
GO



/* Query #51012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable2
   @p0 INT
AS
delete from MSP_VIEW_RES_ENT where ENT_ResourceUniqueID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewEntRes_DeleteViewTable2 TO MSProjectServerRole
GO



/* Query #51020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst0
AS
select * from MSP_VIEW_RES_STD WITH (READPAST) where ResourceUniqueID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst0 TO MSProjectServerRole
GO



/* Query #51021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst1
AS
select * from MSP_VIEW_RES_CF WITH (READPAST) where CF_ResourceUniqueID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst1 TO MSProjectServerRole
GO



/* Query #51022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst2
AS
select * from MSP_VIEW_RES_ENT WITH (READPAST) where ENT_ResourceUniqueID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewEntRes_SelectEmptyRst2 TO MSProjectServerRole
GO



/* Query #51110 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_DeleteViewTable0
   @p0 INT
AS
delete from MSP_VIEW_RES_TP_BY_DAY where ResourceUniqueID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_DeleteViewTable0 TO MSProjectServerRole
GO



/* Query #51120 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_SelectEmptyRst0
AS
select * from MSP_VIEW_RES_TP_BY_DAY WITH (READPAST) where ResourceUniqueID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ViewResourceAssignmentByDay_SelectEmptyRst0 TO MSProjectServerRole
GO


-- End viewsps.sql
