Select MSP_WEB_STATUS_RESPONSES.*, 
       WRES_ID_MGR 
  From MSP_WEB_STATUS_RESPONSES, 
       MSP_WEB_STATUS_REPORTS 
 Where WREPORT_IS_ENABLED <> 0 
   and MSP_WEB_STATUS_RESPONSES.WSR_ID = @p0 
   and WSUBMIT_STATUS = 2 
   and MSP_WEB_STATUS_RESPONSES.WSR_ID = MSP_WEB_STATUS_REPORTS.WSR_ID 
 Order By WSUBMIT_DATE
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllResponsesResNameForSRID TO MSProjectServerRole
GO



/* Query #10113 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetRespFlagsForSRID
   @p0 INT
AS
--Select WRESP_IS_NEW_RESPONSE,WRESP_IS_MERGED From MSP_WEB_STATUS_RESPONSES Where WSR_ID=@p0 and WSUBMIT_STATUS=2 Order By WSUBMIT_DATE RETURN
Select WRESP_IS_NEW_RESPONSE, 
       WRESP_IS_MERGED 
  From MSP_WEB_STATUS_RESPONSES 
 Where WSR_ID = @p0 
   and WSUBMIT_STATUS = 2 
 Order By WSUBMIT_DATE
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetRespFlagsForSRID TO MSProjectServerRole
GO



/* Query #10115 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForResIDAndType
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Delete from MSP_WEB_WORK Where WRES_ID=@p0 and WASSN_ID=@p1 and WWORK_TYPE=@p2 RETURN(0)
Delete 
  from MSP_WEB_WORK 
 Where WRES_ID = @p0 
   and WASSN_ID = @p1 
   and WWORK_TYPE = @p2
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForResIDAndType TO MSProjectServerRole
GO



/* Query #10117 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDistinctCustomFieldsForResIDSortByName
   @p0 INT,
   @p1 INT
AS
--Select Distinct MSP_WEB_WORKGROUP_FIELDS_INFO.CUSTFIELD_INFO_ID,CUSTFIELD_NAME From MSP_WEB_WORKGROUP_FIELDS_INFO, MSP_WEB_PROJECT_WORKGROUP_INFO, MSP_WEB_ASSIGNMENTS, MSP_WEB_WORKGROUP_FIELDS Where MSP_WEB_WORKGROUP_FIELDS_INFO.FIELD_ID=MSP_WEB_WORKGROUP_FIELDS.FIELD_ID and MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_WORKGROUP_FIELDS.WASSN_ID and MSP_WEB_WORKGROUP_FIELDS_INFO.CUSTFIELD_INFO_ID=MSP_WEB_PROJECT_WORKGROUP_INFO.CUSTFIELD_INFO_ID and MSP_WEB_PROJECT_WORKGROUP_INFO.WPROJ_ID=MSP_WEB_ASSIGNMENTS.WPROJ_ID and MSP_WEB_ASSIGNMENTS.WRES_ID=@p0 Order By CUSTFIELD_NAME RETURN
-- Conversion to ANSI INNER JOIN
Select Distinct MSP_WEB_WORKGROUP_FIELDS_INFO.CUSTFIELD_INFO_ID, 
                ((CASE WHEN CUSTFIELD_NAME is null OR CUSTFIELD_NAME=N'' THEN CONV_STRING ELSE CUSTFIELD_NAME END)) as CUSTFIELD_NAME 
  From MSP_WEB_WORKGROUP_FIELDS_INFO 
       INNER JOIN MSP_WEB_WORKGROUP_FIELDS 
          ON MSP_WEB_WORKGROUP_FIELDS_INFO.FIELD_ID = MSP_WEB_WORKGROUP_FIELDS.FIELD_ID 
       INNER JOIN MSP_WEB_PROJECT_WORKGROUP_INFO 
          ON MSP_WEB_WORKGROUP_FIELDS_INFO.CUSTFIELD_INFO_ID = MSP_WEB_PROJECT_WORKGROUP_INFO.CUSTFIELD_INFO_ID 
       INNER JOIN MSP_WEB_ASSIGNMENTS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_WORKGROUP_FIELDS.WASSN_ID 
       LEFT JOIN MSP_WEB_CONVERSIONS ON (MSP_WEB_WORKGROUP_FIELDS_INFO.CONV_VALUE=MSP_WEB_CONVERSIONS.CONV_VALUE and LANG_ID=@p1)
 Where MSP_WEB_PROJECT_WORKGROUP_INFO.WPROJ_ID = MSP_WEB_ASSIGNMENTS.WPROJ_ID 
   and MSP_WEB_ASSIGNMENTS.WRES_ID = @p0 
 Order By CUSTFIELD_NAME

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDistinctCustomFieldsForResIDSortByName TO MSProjectServerRole
GO



/* Query #10118 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteExtraLateReports
   @p0 INT,
   @p1 INT,
   @p2 DATETIME,
   @p3 DATETIME,
   @p4 DATETIME,
   @p5 DATETIME
AS
--Delete from MSP_WEB_STATUS_RESPONSES Where WRES_ID=@p0 and WSR_ID=@p1 and WSRESP_PERIOD_START>=@p2 and WSRESP_PERIOD_START<@p3 and WSRESP_PERIOD_FINISH>=@p4 and WSRESP_PERIOD_FINISH<@p5 and WSUBMIT_STATUS=0 RETURN(0)
Delete 
  from MSP_WEB_STATUS_RESPONSES 
 Where WRES_ID = @p0 
   and WSR_ID = @p1 
   and WSRESP_PERIOD_START >= @p2 
   and WSRESP_PERIOD_START < @p3 
   and WSRESP_PERIOD_FINISH >= @p4 
   and WSRESP_PERIOD_FINISH < @p5 
   and WSUBMIT_STATUS = 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteExtraLateReports TO MSProjectServerRole
GO



/* Query #10119 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetExistingReportsAfterDueOnDate
   @p0 INT,
   @p1 INT,
   @p2 DATETIME,
   @p3 DATETIME
AS
--Select WRESP_ID,WSRESP_PERIOD_START,WSRESP_PERIOD_FINISH from MSP_WEB_STATUS_RESPONSES Where WRES_ID=@p0 and WSR_ID=@p1 and WSRESP_PERIOD_START>=@p2 and WSRESP_PERIOD_START<@p3 and WSUBMIT_STATUS>0 Order By WSRESP_PERIOD_START RETURN
Select WRESP_ID, 
       WSRESP_PERIOD_START, 
       WSRESP_PERIOD_FINISH 
  from MSP_WEB_STATUS_RESPONSES 
 Where WRES_ID = @p0 
   and WSR_ID = @p1 
   and WSRESP_PERIOD_START >= @p2 
   and WSRESP_PERIOD_START < @p3 
   and WSUBMIT_STATUS > 0 
 Order By WSRESP_PERIOD_START
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetExistingReportsAfterDueOnDate TO MSProjectServerRole
GO



/* Query #10121 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectCFInfoForFileID
   @p0 INT
AS
--Select * From MSP_WEB_PROJECT_WORKGROUP_INFO Where WPROJ_ID=@p0 RETURN
Select * 
  From MSP_WEB_PROJECT_WORKGROUP_INFO 
 Where WPROJ_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectCFInfoForFileID TO MSProjectServerRole
GO



/* Query #10124 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgID
   @p0 INT
AS
--Delete from MSP_WEB_MESSAGES where WMSG_ID=@p0 RETURN(0)
Delete 
  from MSP_WEB_MESSAGES 
 where WMSG_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgID TO MSProjectServerRole
GO



/* Query #10125 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnIDForMsgID
   @p0 INT
AS
--Delete from MSP_WEB_MESSAGES_ASSIGNMENTS where WMSG_ID=@p0 RETURN(0)
Delete 
  from MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WMSG_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnIDForMsgID TO MSProjectServerRole
GO



/* Query #10127 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CountOfOverdueStatusReports
   @p0 INT,
   @p1 DATETIME
AS
--Select count(*) from MSP_WEB_STATUS_RESPONSES where WRES_ID=@p0 and WSRESP_PERIOD_FINISH < @p1 and WSR_ID in (select WSR_ID from MSP_WEB_STATUS_REPORTS where WREPORT_IS_ENABLED<>0) and WSUBMIT_STATUS<>2 RETURN
Select count(*) 
  from MSP_WEB_STATUS_RESPONSES 
 where WRES_ID = @p0 
   and WSRESP_PERIOD_FINISH < @p1 
   and WSR_ID in (select WSR_ID 
                    from MSP_WEB_STATUS_REPORTS 
                   where WREPORT_IS_ENABLED <> 0) 
   and WSUBMIT_STATUS <> 2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CountOfOverdueStatusReports TO MSProjectServerRole
GO



/* Query #10128 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CountOfNewTasks
   @p0 INT
AS
--Select count(*) from MSP_WEB_ASSIGNMENTS Where WRES_ID=@p0 and WASSN_IS_CONFIRMED<>0 and WASSN_IS_NEW_ASSN<>0 and WASSN_REMOVED_BY_RESOURCE=0 and WASSN_DELETED_IN_PROJ=0 RETURN
Select count(*) 
  from MSP_WEB_ASSIGNMENTS 
 Where WRES_ID = @p0 
   and WASSN_IS_CONFIRMED <> 0 
   and WASSN_IS_NEW_ASSN <> 0 
   and WASSN_REMOVED_BY_RESOURCE = 0
   and WASSN_DELETED_IN_PROJ = 0
   and ASSN_BOOKING_TYPE = 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CountOfNewTasks TO MSProjectServerRole
GO



/* Query #10129 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CountOfOverdueTasks
   @p0 INT,
   @p1 DATETIME
AS
--Select count(*) from MSP_WEB_ASSIGNMENTS Where WRES_ID=@p0 and WASSN_IS_CONFIRMED<>0 and ASSN_FINISH_DATE < @p1 and ASSN_REM_WORK<>0 and WASSN_REMOVED_BY_RESOURCE=0 RETURN
Select count(*) 
  from MSP_WEB_ASSIGNMENTS 
 Where WRES_ID = @p0 
   and WASSN_IS_CONFIRMED <> 0 
   and ASSN_FINISH_DATE < @p1 
   and ASSN_REM_WORK <> 0 
   and WASSN_REMOVED_BY_RESOURCE = 0
   and ASSN_BOOKING_TYPE = 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CountOfOverdueTasks TO MSProjectServerRole
GO



/* Query #10136 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CountOfAcceptedTasksForMsgID
   @p0 INT
AS
--Select count(*) from MSP_WEB_ASSIGNMENTS Where WASSN_CREATED_BY_RES=4 AND WASSN_ID in (select WASSN_ID FROM MSP_WEB_MESSAGES_ASSIGNMENTS WHERE WMSG_ID=@p0) RETURN
Select count(*) 
  from MSP_WEB_ASSIGNMENTS 
 Where WASSN_CREATED_BY_RES = 4 
   AND WASSN_ID in (select WASSN_ID 
                      FROM MSP_WEB_MESSAGES_ASSIGNMENTS 
                     WHERE WMSG_ID = @p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CountOfAcceptedTasksForMsgID TO MSProjectServerRole
GO



/* Query #10137 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDelegPendingAssnForFileId
   @p0 INT
AS
--select WASSN_ID from MSP_WEB_ASSIGNMENTS Where WPROJ_ID=@p0 and WASSN_IS_DELEGATED<>0 RETURN
select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 Where WPROJ_ID = @p0 
   and WASSN_IS_DELEGATED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDelegPendingAssnForFileId TO MSProjectServerRole
GO



/* Query #10144 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_LeadAndDelegeeNamesFromMsgID
   @p0 INT,
   @p1 INT
AS
--SELECT DISTINCT MSP_WEB_RESOURCES.RES_NAME FROM MSP_WEB_RESOURCES,MSP_WEB_MESSAGES_ASSIGNMENTS,MSP_WEB_ASSIGNMENTS WHERE MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID AND MSP_WEB_MESSAGES_ASSIGNMENTS.WMSG_ID=@p0 AND MSP_WEB_RESOURCES.WRES_ID<>@p1 AND (MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_ASSIGNMENTS.WRES_ID OR MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_ASSIGNMENTS.WRES_ID_TEAM_LEAD) RETURN
-- Conversion to ANSI INNER JOIN
SELECT DISTINCT MSP_WEB_RESOURCES.RES_NAME 
  FROM MSP_WEB_RESOURCES, 
       MSP_WEB_MESSAGES_ASSIGNMENTS 
       INNER JOIN MSP_WEB_ASSIGNMENTS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID 
 WHERE MSP_WEB_MESSAGES_ASSIGNMENTS.WMSG_ID = @p0 
   AND MSP_WEB_RESOURCES.WRES_ID <> @p1 
   AND (MSP_WEB_RESOURCES.WRES_ID = MSP_WEB_ASSIGNMENTS.WRES_ID 
            OR MSP_WEB_RESOURCES.WRES_ID = MSP_WEB_ASSIGNMENTS.WRES_ID_TEAM_LEAD)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_LeadAndDelegeeNamesFromMsgID TO MSProjectServerRole
GO

/* Query #10145 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CountOfPendingApprovals
   @p0 INT,
   @p1 DATETIME
AS
SELECT WWA.WPRD_START_DATE,WWA.WPRD_FINISH_DATE, COUNT(DISTINCT WWA.WRES_ID) AS TCOUNT 
FROM MSP_WEB_WORK_APPROVAL WWA 
WHERE WWA.WAPPROVAL_STATUS = 0 AND DATEADD (mm,3,WWA.WPRD_FINISH_DATE)>=@p1
		AND WWA.WRES_ID in (
	    -- Permission 212: Approve timesheet permission
            select WRES_ID from MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p0, 212, -1)
         )
GROUP BY WWA.WPRD_START_DATE, WWA.WPRD_FINISH_DATE  
ORDER BY WWA.WPRD_START_DATE
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CountOfPendingApprovals TO MSProjectServerRole
GO

/* Query #10146 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CountOfUnsubmittedTimesheets
   @p0 INT,
   @p1 DATETIME
AS
SELECT WTP.WPRD_START_DATE, WTP.WPRD_FINISH_DATE, COUNT (DISTINCT WA.WRES_ID) AS TCOUNT
FROM MSP_WEB_TIME_PERIODS WTP INNER JOIN MSP_WEB_ASSIGNMENTS WA ON (WTP.WPRD_ID>=100 AND ((WTP.WPRD_START_DATE< WA.ASSN_FINISH_DATE AND WTP.WPRD_FINISH_DATE> WA.ASSN_START_DATE) OR (((WA.WASSN_ACTUALS_PENDING <> 0) OR (WA.WASSN_PCT_COMP< 100 AND WASSN_PCT_COMP>0)) AND WA.ASSN_START_DATE<= WTP.WPRD_FINISH_DATE))) 
     INNER JOIN MSP_WEB_PROJECTS ON (WA.WPROJ_ID = MSP_WEB_PROJECTS.WPROJ_ID)

WHERE 
   (WA.WASSN_IS_CONFIRMED<>0 OR MSP_WEB_PROJECTS.WPROJ_ADMINPROJECT<>0)
    AND WA.WASSN_REMOVED_BY_RESOURCE=0
    AND MSP_WEB_PROJECTS.WPROJ_TYPE <> 3
    AND DATEADD (mm,3,WTP.WPRD_FINISH_DATE)>=@p1 AND @p1>WTP.WPRD_FINISH_DATE
		AND WA.WRES_ID in (
	    -- Permission 212: Approve timesheet permission
            select WRES_ID from MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p0, 212, -1)
         )
    AND NOT EXISTS (SELECT * FROM MSP_WEB_WORK_APPROVAL WAA WHERE WAA.WRES_ID=WA.WRES_ID AND WAA.WPRD_START_DATE = WTP.WPRD_START_DATE AND WAA.WPRD_FINISH_DATE = WTP.WPRD_FINISH_DATE )
GROUP BY WTP.WPRD_START_DATE,WTP.WPRD_FINISH_DATE
ORDER BY WTP.WPRD_START_DATE
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CountOfUnsubmittedTimesheets TO MSProjectServerRole
GO

/* Query #10147 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CountOfUnsubmittedTasks
   @p0 INT,
   @p1 DATETIME
AS
SELECT DISTINCT WTP.WPRD_START_DATE, WTP.WPRD_FINISH_DATE
FROM MSP_WEB_TIME_PERIODS WTP INNER JOIN MSP_WEB_ASSIGNMENTS WA ON (WTP.WPRD_START_DATE< WA.ASSN_FINISH_DATE AND WTP.WPRD_FINISH_DATE> WA.ASSN_START_DATE AND WTP.WPRD_ID>=100)
WHERE WA.WRES_ID =@p0
       AND DATEADD (mm,3,WTP.WPRD_FINISH_DATE)>=@p1 AND @p1>WTP.WPRD_FINISH_DATE
       AND NOT EXISTS (SELECT * FROM MSP_WEB_WORK_APPROVAL WAA WHERE WAA.WASSN_ID=WA.WASSN_ID AND WAA.WPRD_START_DATE = WTP.WPRD_START_DATE AND WAA.WPRD_FINISH_DATE = WTP.WPRD_FINISH_DATE AND WAA.WAPPROVAL_STATUS <> 2)
ORDER BY WTP.WPRD_START_DATE

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CountOfUnsubmittedTasks TO MSProjectServerRole
GO


/* Query #10151 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ResponseRespIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WRESP_ID From MSP_WEB_STATUS_RESPONSES Where WRES_ID=@p0 and WRESP_ID=@p1 RETURN
Select WRESP_ID 
  From MSP_WEB_STATUS_RESPONSES 
 Where WRES_ID = @p0 
   and WRESP_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ResponseRespIDCheck TO MSProjectServerRole
GO



/* Query #10152 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UnreqSRIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WRESP_ID From MSP_WEB_STATUS_RESPONSES, MSP_WEB_STATUS_REPORTS Where MSP_WEB_STATUS_RESPONSES.WSR_ID=MSP_WEB_STATUS_REPORTS.WSR_ID and MSP_WEB_STATUS_RESPONSES.WRES_ID=@p0 and MSP_WEB_STATUS_RESPONSES.WSR_ID=@p1 and WREPORT_UNREQUESTED<>0 and WREPORT_IS_ENABLED<>0 RETURN
--Conversion to ANSI INNER JOIN 
Select WRESP_ID 
  From MSP_WEB_STATUS_RESPONSES 
       INNER JOIN MSP_WEB_STATUS_REPORTS 
          ON MSP_WEB_STATUS_RESPONSES.WSR_ID = MSP_WEB_STATUS_REPORTS.WSR_ID 
 Where MSP_WEB_STATUS_RESPONSES.WRES_ID = @p0 
   and MSP_WEB_STATUS_RESPONSES.WSR_ID = @p1 
   and WREPORT_UNREQUESTED <> 0 
   and WREPORT_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UnreqSRIDCheck TO MSProjectServerRole
GO



/* Query #10153 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MgrSRIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WSR_ID From MSP_WEB_STATUS_REPORTS Where WRES_ID_MGR=@p0 and WSR_ID=@p1 and WREPORT_IS_ENABLED<>0 RETURN
Select WSR_ID 
  From MSP_WEB_STATUS_REPORTS 
 Where WRES_ID_MGR = @p0 
   and WSR_ID = @p1 
   and WREPORT_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MgrSRIDCheck TO MSProjectServerRole
GO



/* Query #10154 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_RequestSRIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WSR_ID From MSP_WEB_STATUS_REQUESTS Where WRES_ID_RECEIVER=@p0 and WSR_ID=@p1 RETURN
Select WSR_ID 
  From MSP_WEB_STATUS_REQUESTS 
 Where WRES_ID_RECEIVER = @p0 
   and WSR_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_RequestSRIDCheck TO MSProjectServerRole
GO



/* Query #10155 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MgrRespIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WRESP_ID From MSP_WEB_STATUS_REPORTS,MSP_WEB_STATUS_RESPONSES Where WRES_ID_MGR=@p0 and WRESP_ID=@p1 and WREPORT_IS_ENABLED<>0 and MSP_WEB_STATUS_REPORTS.WSR_ID=MSP_WEB_STATUS_RESPONSES.WSR_ID RETURN
Select WRESP_ID 
  From MSP_WEB_STATUS_REPORTS, 
       MSP_WEB_STATUS_RESPONSES 
 Where WRES_ID_MGR = @p0 
   and WRESP_ID = @p1 
   and WREPORT_IS_ENABLED <> 0 
   and MSP_WEB_STATUS_REPORTS.WSR_ID = MSP_WEB_STATUS_RESPONSES.WSR_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MgrRespIDCheck TO MSProjectServerRole
GO



/* Query #10156 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MgrResIDCheck
   @p0 INT,
   @p1 INT
AS
--Select MSP_WEB_STATUS_REPORTS.WSR_ID From MSP_WEB_STATUS_REPORTS,MSP_WEB_STATUS_REQUESTS Where WREPORT_IS_ENABLED<>0 and WRES_ID_MGR=@p0 and WRES_ID_RECEIVER=@p1 and MSP_WEB_STATUS_REPORTS.WSR_ID=MSP_WEB_STATUS_REQUESTS.WSR_ID RETURN
Select MSP_WEB_STATUS_REPORTS.WSR_ID 
  From MSP_WEB_STATUS_REPORTS, 
       MSP_WEB_STATUS_REQUESTS 
 Where WREPORT_IS_ENABLED <> 0 
   and WRES_ID_MGR = @p0 
   and WRES_ID_RECEIVER = @p1 
   and MSP_WEB_STATUS_REPORTS.WSR_ID = MSP_WEB_STATUS_REQUESTS.WSR_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MgrResIDCheck TO MSProjectServerRole
GO



/* Query #10157 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DistRespIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WRESP_ID From MSP_WEB_STATUS_DISTRIBUTION Where WRES_ID_DISTR_RECIP=@p0 and WRESP_ID=@p1 RETURN
Select WRESP_ID 
  From MSP_WEB_STATUS_DISTRIBUTION 
 Where WRES_ID_DISTR_RECIP = @p0 
   and WRESP_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DistRespIDCheck TO MSProjectServerRole
GO



/* Query #10158 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DistSRIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WSR_ID From MSP_WEB_STATUS_RESPONSES,MSP_WEB_STATUS_DISTRIBUTION Where WRES_ID_DISTR_RECIP=@p0 and WSR_ID=@p1 and MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID=MSP_WEB_STATUS_RESPONSES.WRESP_ID RETURN
-- Conversion to ANSI INNER JOIN
Select WSR_ID 
  From MSP_WEB_STATUS_RESPONSES 
       INNER JOIN MSP_WEB_STATUS_DISTRIBUTION 
          ON MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID = MSP_WEB_STATUS_RESPONSES.WRESP_ID 
 Where WRES_ID_DISTR_RECIP = @p0 
   and WSR_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DistSRIDCheck TO MSProjectServerRole
GO



/* Query #10159 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DistWRESIDCheck
   @p0 INT,
   @p1 INT
AS
--Select WSR_ID From MSP_WEB_STATUS_RESPONSES,MSP_WEB_STATUS_DISTRIBUTION Where WRES_ID_DISTR_RECIP=@p0 and WRES_ID=@p1 and MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID=MSP_WEB_STATUS_RESPONSES.WRESP_ID RETURN
--Conversion to ANSI INNER JOIN
Select WSR_ID 
  From MSP_WEB_STATUS_RESPONSES 
       INNER JOIN MSP_WEB_STATUS_DISTRIBUTION 
          ON MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID = MSP_WEB_STATUS_RESPONSES.WRESP_ID 
 Where WRES_ID_DISTR_RECIP = @p0 
   and WRES_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DistWRESIDCheck TO MSProjectServerRole
GO



/* Query #10160 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyStatusResponses
AS
--Select * From MSP_WEB_STATUS_RESPONSES Where WRESP_ID=-1 RETURN
Select * 
  From MSP_WEB_STATUS_RESPONSES WITH (READPAST)
 Where WRESP_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyStatusResponses TO MSProjectServerRole
GO



/* Query #10161 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyStatusDistribution
AS
--Select * From MSP_WEB_STATUS_DISTRIBUTION Where WRESP_ID=-1 RETURN
Select * 
  From MSP_WEB_STATUS_DISTRIBUTION WITH (READPAST) 
 Where WRESP_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyStatusDistribution TO MSProjectServerRole
GO



/* Query #10162 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyDeleg
AS
--Select * From MSP_WEB_DELEGATIONS Where WDELEG_ID=-1 RETURN
Select * 
  From MSP_WEB_DELEGATIONS WITH (READPAST) 
 Where WDELEG_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyDeleg TO MSProjectServerRole
GO



/* Query #10163 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyDelegMap
AS
--Select * From MSP_WEB_DELEGATION_ASSIGNMENTS Where WDELEG_ID=-1 RETURN
Select * 
  From MSP_WEB_DELEGATION_ASSIGNMENTS WITH (READPAST) 
 Where WDELEG_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyDelegMap TO MSProjectServerRole
GO



/* Query #10164 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResourceListForExport
   @p0 INT
AS
--Select RES_NAME,RES_PHONETICS,WRES_USE_NT_LOGON,WRES_EMAIL,WRES_IS_MANAGER,WRES_IS_ADMIN From MSP_WEB_RESOURCES Where WRES_ID<>@p0 and WRES_IS_ENABLED<>0 RETURN
Select RES_NAME, 
       RES_PHONETICS, 
       WRES_USE_NT_LOGON, 
       WRES_NT_ACCOUNT,
       WRES_EMAIL, 
       WRES_IS_MANAGER, 
       WRES_IS_ADMIN 
  From MSP_WEB_RESOURCES R
       INNER JOIN dbo.MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p0, 1014, -1) A
       ON ( R.WRES_ID <> 1 and R.WRES_IS_ENABLED <> 0 and R.WRES_ID = A.WRES_ID )

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResourceListForExport TO MSProjectServerRole
GO



/* Query #10173 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnForDelegUpdate
   @p0 INT
AS
--SELECT * FROM MSP_WEB_ASSIGNMENTS Where MSP_WEB_ASSIGNMENTS.WASSN_ID=@p0 RETURN
SELECT * 
  FROM MSP_WEB_ASSIGNMENTS 
 Where MSP_WEB_ASSIGNMENTS.WASSN_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnForDelegUpdate TO MSProjectServerRole
GO



/* Query #10175 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnForDelegUpdateWDelegator
   @p0 INT
AS
--SELECT TASK_ID,WPROJ_ID,WASSN_DELEG_PENDING,WRES_ID_DELEGATOR FROM MSP_WEB_ASSIGNMENTS,MSP_WEB_DELEGATIONS Where MSP_WEB_ASSIGNMENTS.WASSN_ID=@p0 and MSP_WEB_ASSIGNMENTS.WASSN_LAST_DELEG_ID=MSP_WEB_DELEGATIONS.WDELEG_ID RETURN
--Conversion to ANSI INNER JOIN
SELECT TASK_UID, 
       WPROJ_ID, 
       WASSN_DELEG_PENDING, 
       WRES_ID_DELEGATOR 
  FROM MSP_WEB_ASSIGNMENTS WA 
       INNER JOIN MSP_WEB_TRANSACTIONS WT ON WA.WASSN_ID = WT.WASSN_ID
       INNER JOIN MSP_WEB_DELEGATIONS WD ON WT.WDELEG_ID = WD.WDELEG_ID
 WHERE WTRANS_ID=@p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnForDelegUpdateWDelegator TO MSProjectServerRole
GO



/* Query #10176 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetTaskProjNameForAssnId
   @p0 INT
AS
--Select TASK_NAME,WASSN_REQUEST_UPDATE,WASSN_DELEG_PENDING,PROJ_NAME,WRES_ID_TEAM_LEAD,RES_NAME From (MSP_WEB_ASSIGNMENTS INNER JOIN MSP_WEB_PROJECTS ON MSP_WEB_ASSIGNMENTS.WPROJ_ID=MSP_WEB_PROJECTS.WPROJ_ID) LEFT JOIN MSP_WEB_RESOURCES ON MSP_WEB_ASSIGNMENTS.WRES_ID_TEAM_LEAD=MSP_WEB_RESOURCES.WRES_ID Where MSP_WEB_ASSIGNMENTS.WASSN_ID=@p0 RETURN
Select TASK_NAME, 
       WASSN_REQUEST_UPDATE, 
       WASSN_DELEG_PENDING, 
       PROJ_NAME, 
       WRES_ID_TEAM_LEAD, 
       RES_NAME 
  From (MSP_WEB_ASSIGNMENTS 
       INNER JOIN MSP_WEB_PROJECTS 
          ON MSP_WEB_ASSIGNMENTS.WPROJ_ID = MSP_WEB_PROJECTS.WPROJ_ID) 
       LEFT JOIN MSP_WEB_RESOURCES 
         ON MSP_WEB_ASSIGNMENTS.WRES_ID_TEAM_LEAD = MSP_WEB_RESOURCES.WRES_ID 
 Where MSP_WEB_ASSIGNMENTS.WASSN_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetTaskProjNameForAssnId TO MSProjectServerRole
GO



/* Query #10177 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDelegHistForAssn
   @p0 INT
AS
--SELECT MSP_WEB_DELEGATIONS.WDELEG_REJECT, WR1.RES_NAME AS TDelegatorName, WR2.RES_NAME AS TDelegeeName, WR3.RES_NAME AS TLeadName, MSP_WEB_DELEGATIONS.WDELEG_DATE FROM ((((MSP_WEB_ASSIGNMENTS INNER JOIN MSP_WEB_DELEGATION_ASSIGNMENTS ON MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_DELEGATION_ASSIGNMENTS.WASSN_ID) INNER JOIN MSP_WEB_DELEGATIONS ON MSP_WEB_DELEGATION_ASSIGNMENTS.WDELEG_ID = MSP_WEB_DELEGATIONS.WDELEG_ID) INNER JOIN MSP_WEB_RESOURCES WR1 ON MSP_WEB_DELEGATIONS.WRES_ID_DELEGATOR = WR1.WRES_ID) INNER JOIN MSP_WEB_RESOURCES WR2 ON MSP_WEB_DELEGATIONS.WRES_ID_DELEGATEE = WR2.WRES_ID) LEFT JOIN MSP_WEB_RESOURCES WR3 ON MSP_WEB_ASSIGNMENTS.WRES_ID_TEAM_LEAD = WR3.WRES_ID WHERE MSP_WEB_ASSIGNMENTS.WASSN_ID=@p0 Order By WDELEG_DATE RETURN
SELECT MSP_WEB_DELEGATIONS.WDELEG_REJECT, 
       WR1.RES_NAME AS TDelegatorName, 
       WR2.RES_NAME AS TDelegeeName, 
       WR3.RES_NAME AS TLeadName, 
       MSP_WEB_DELEGATIONS.WDELEG_DATE 
  FROM ((((MSP_WEB_ASSIGNMENTS 
       INNER JOIN MSP_WEB_DELEGATION_ASSIGNMENTS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_DELEGATION_ASSIGNMENTS.WASSN_ID) 
       INNER JOIN MSP_WEB_DELEGATIONS 
          ON MSP_WEB_DELEGATION_ASSIGNMENTS.WDELEG_ID = MSP_WEB_DELEGATIONS.WDELEG_ID) 
       INNER JOIN MSP_WEB_RESOURCES WR1 
          ON MSP_WEB_DELEGATIONS.WRES_ID_DELEGATOR = WR1.WRES_ID) 
       INNER JOIN MSP_WEB_RESOURCES WR2 
          ON MSP_WEB_DELEGATIONS.WRES_ID_DELEGATEE = WR2.WRES_ID) 
       LEFT JOIN MSP_WEB_RESOURCES WR3 
         ON MSP_WEB_ASSIGNMENTS.WRES_ID_TEAM_LEAD = WR3.WRES_ID 
 WHERE MSP_WEB_ASSIGNMENTS.WASSN_ID = @p0 
 Order By WDELEG_DATE
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDelegHistForAssn TO MSProjectServerRole
GO



/* Query #10180 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllActiveUsersExceptYouOBName
   @p0 INT,
   @p1 INT
AS
--Select WRES_ID,RES_NAME From MSP_WEB_RESOURCES Where WRES_ID<>@p0 and WRES_IS_ENABLED<>0 Order By RES_NAME RETURN
Select WR.WRES_ID, 
       RES_NAME 
  From MSP_WEB_RESOURCES WR inner join MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p0, @p1, -1) as SEC on WR.WRES_ID=SEC.WRES_ID
 Where WR.WRES_ID <> @p0 
   and WRES_IS_ENABLED = 1
   and WRES_CAN_LOGIN = 1
   and WRES_COUNT_LICENSE = 1
 Order By RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllActiveUsersExceptYouOBName TO MSProjectServerRole
GO



/* Query #10181 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssignmentForAssnID
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_ASSIGNMENTS set WRES_ID=-1, WASSN_IS_DELEGATED=1, WASSN_LAST_DELEG_ID=-1, WRES_ID_TEAM_LEAD=-1, WASSN_DELEG_PENDING=0 Where WASSN_ID=@p0 RETURN(0)
update MSP_WEB_ASSIGNMENTS 
   set WRES_ID = -1, 
       WASSN_IS_DELEGATED = 1, 
       WASSN_LAST_DELEG_ID = -1, 
       WRES_ID_TEAM_LEAD = -1, 
       WASSN_DELEG_PENDING = @p1 
 Where WASSN_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssignmentForAssnID TO MSProjectServerRole
GO



/* Query #10182 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ReplaceDelegAssnWithNewAssn
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--update MSP_WEB_DELEGATION_ASSIGNMENTS set WASSN_ID=@p2 where WDELEG_ID=@p0 and WASSN_ID=@p1 RETURN(0)
update MSP_WEB_DELEGATION_ASSIGNMENTS 
   set WASSN_ID = @p2 
 where WDELEG_ID = @p0 
   and WASSN_ID = @p1
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ReplaceDelegAssnWithNewAssn TO MSProjectServerRole
GO



/* Query #10183 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMatchingAssnForDelegee
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Select WASSN_IS_NEW_ASSN,WASSN_REMOVED_BY_RESOURCE,WASSN_ID,ASSN_WORK,ASSN_REM_WORK,WASSN_PCT_COMP,WASSN_LAST_DELEG_ID,WASSN_DELEG_PENDING,WRES_ID_TEAM_LEAD,WASSN_IS_DELEGATED,WASSN_REQUEST_UPDATE From MSP_WEB_ASSIGNMENTS Where WRES_ID=@p0 and TASK_UID=@p1 and WPROJ_ID=@p2 and TASK_IS_SUMMARY=0 and WASSN_DELETED_IN_PROJ=0 RETURN
Select WASSN_IS_NEW_ASSN, 
       WASSN_REMOVED_BY_RESOURCE, 
       WASSN_ID, 
       ASSN_WORK, 
       ASSN_REM_WORK, 
       WASSN_PCT_COMP, 
       WASSN_LAST_DELEG_ID, 
       WASSN_DELEG_PENDING, 
       WRES_ID_TEAM_LEAD, 
       WASSN_IS_DELEGATED, 
       WASSN_REQUEST_UPDATE 
  From MSP_WEB_ASSIGNMENTS with (readpast)

 Where WRES_ID = @p0 
   and TASK_UID = @p1 
   and WPROJ_ID = @p2 
   and TASK_IS_SUMMARY = 0 
   and WASSN_DELETED_IN_PROJ = 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMatchingAssnForDelegee TO MSProjectServerRole
GO



/* Query #10184 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ReplaceAllDelegAssnWithNewAssn
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_DELEGATION_ASSIGNMENTS set WASSN_ID=@p1 where WASSN_ID=@p0 and not WDELEG_ID in (Select WDA.WDELEG_ID From MSP_WEB_DELEGATION_ASSIGNMENTS WDA Where WDA.WASSN_ID=@p1) RETURN(0)
update MSP_WEB_DELEGATION_ASSIGNMENTS 
   set WASSN_ID = @p1 
 where WASSN_ID = @p0 
   and not WDELEG_ID in (Select WDA.WDELEG_ID 
                           From MSP_WEB_DELEGATION_ASSIGNMENTS WDA 
                          Where WDA.WASSN_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ReplaceAllDelegAssnWithNewAssn TO MSProjectServerRole
GO



/* Query #10185 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDelegAssnsForReplication
   @p0 INT,
   @p1 INT
AS
--Select * From MSP_WEB_DELEGATION_ASSIGNMENTS Where WASSN_ID=@p0 and not WDELEG_ID in (Select WDA.WDELEG_ID From MSP_WEB_DELEGATION_ASSIGNMENTS WDA Where WDA.WASSN_ID=@p1) RETURN
Select * 
  From MSP_WEB_DELEGATION_ASSIGNMENTS 
 Where WASSN_ID = @p0 
   and not WDELEG_ID in (Select WDA.WDELEG_ID 
                           From MSP_WEB_DELEGATION_ASSIGNMENTS WDA 
                          Where WDA.WASSN_ID = @p1)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDelegAssnsForReplication TO MSProjectServerRole
GO



/* Query #10189 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllMyTasksThatIReportToLeads
   @p0 INT
AS
--Select WASSN_ID,WASSN_RESOURCE_UPDATE,WASSN_REQUEST_UPDATE,WRES_ID_TEAM_LEAD,WASSN_SEND_UPDATE_DATE,WA.WPROJ_ID,PROJ_NAME From MSP_WEB_ASSIGNMENTS WA,MSP_WEB_PROJECTS WP Where WA.WPROJ_ID=WP.WPROJ_ID and WA.WRES_ID=@p0 and WRES_ID_TEAM_LEAD is Not Null and WASSN_SEND_UPDATE_NEEDED<>0 and WASSN_REMOVED_BY_RESOURCE=0 Order By WA.WPROJ_ID,WRES_ID_TEAM_LEAD RETURN
--Conversion to ANSI INNER JOIN
Select WASSN_ID, 
       WASSN_RESOURCE_UPDATE, 
       WASSN_REQUEST_UPDATE, 
       WRES_ID_TEAM_LEAD, 
       WASSN_SEND_UPDATE_DATE, 
       WA.WPROJ_ID, 
       PROJ_NAME 
  From MSP_WEB_ASSIGNMENTS WA 
       INNER JOIN MSP_WEB_PROJECTS WP 
          ON WA.WPROJ_ID = WP.WPROJ_ID 
 Where WA.WRES_ID = @p0 
   and WRES_ID_TEAM_LEAD is Not Null 
   and WASSN_SEND_UPDATE_NEEDED <> 0 
   and WASSN_REMOVED_BY_RESOURCE = 0 
 Order By WA.WPROJ_ID, 
          WRES_ID_TEAM_LEAD
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllMyTasksThatIReportToLeads TO MSProjectServerRole
GO



/* Query #10190 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetRequestUpdateFlagForTeamStatusMsg
   @p0 INT
AS
--Update MSP_WEB_ASSIGNMENTS set WASSN_REQUEST_UPDATE=0,WASSN_RESOURCE_UPDATE=0 where WASSN_ID in (Select MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID From MSP_WEB_MESSAGES_ASSIGNMENTS Where WMSG_ID=@p0) RETURN(0)
Update MSP_WEB_ASSIGNMENTS 
   set WASSN_REQUEST_UPDATE = 0, 
       WASSN_RESOURCE_UPDATE = 0 
 where WASSN_ID in (Select MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID 
                      From MSP_WEB_MESSAGES_ASSIGNMENTS 
                     Where WMSG_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetRequestUpdateFlagForTeamStatusMsg TO MSProjectServerRole
GO



/* Query #10200 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAllSRRespForResID
   @p0 INT
AS
--Delete from MSP_WEB_STATUS_RESPONSES Where WRES_ID=@p0 RETURN(0)
Delete 
  from MSP_WEB_STATUS_RESPONSES 
 Where WRES_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAllSRRespForResID TO MSProjectServerRole
GO



/* Query #10201 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAllSRReqForResID
   @p0 INT
AS
--Delete from MSP_WEB_STATUS_REQUESTS Where WRES_ID_RECEIVER=@p0 RETURN(0)
Delete 
  from MSP_WEB_STATUS_REQUESTS 
 Where WRES_ID_RECEIVER = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAllSRReqForResID TO MSProjectServerRole
GO



/* Query #10202 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAllSRDistForResID
   @p0 INT
AS
--Delete from MSP_WEB_STATUS_DISTRIBUTION Where WRES_ID_DISTR_RECIP=@p0 RETURN(0)
Delete 
  from MSP_WEB_STATUS_DISTRIBUTION 
 Where WRES_ID_DISTR_RECIP = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAllSRDistForResID TO MSProjectServerRole
GO



/* Query #10203 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAllActualsForResID
   @p0 INT
AS
--Delete from MSP_WEB_WORK Where WRES_ID=@p0 RETURN(0)
Delete 
  from MSP_WEB_WORK 
 Where WRES_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAllActualsForResID TO MSProjectServerRole
GO



/* Query #10204 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectAllMsgForResID
   @p0 INT
AS
--Select WMSG_ID From MSP_WEB_MESSAGES Where WRES_ID_RECEIVER=@p0 RETURN
Select WMSG_ID 
  From MSP_WEB_MESSAGES 
 Where WRES_ID_RECEIVER = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectAllMsgForResID TO MSProjectServerRole
GO



/* Query #10205 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectAllAssignForResID
   @p0 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS Where WRES_ID=@p0 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 Where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectAllAssignForResID TO MSProjectServerRole
GO



/* Query #10206 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAllCFForAssnID
   @p0 INT
AS
--Delete from MSP_WEB_WORKGROUP_FIELDS Where WASSN_ID=@p0 RETURN(0)
Delete 
  from MSP_WEB_WORKGROUP_FIELDS 
 Where WASSN_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAllCFForAssnID TO MSProjectServerRole
GO



/* Query #10207 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectAssignForProjID
   @p0 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS Where WPROJ_ID=@p0 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 Where WPROJ_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectAssignForProjID TO MSProjectServerRole
GO



/* Query #10209 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectAllMsgForProjID
   @p0 INT
AS
--Select WMSG_ID From MSP_WEB_MESSAGES Where WPROJ_ID=@p0 RETURN
Select WMSG_ID 
  From MSP_WEB_MESSAGES 
 Where WPROJ_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectAllMsgForProjID TO MSProjectServerRole
GO



/* Query #10210 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectAllSRReqForResID
   @p0 INT
AS
--Select * From MSP_WEB_STATUS_REPORTS Where WRES_ID_MGR=@p0 and WREPORT_IS_ENABLED<>0 Order By WREPORT_NAME RETURN
Select * 
  From MSP_WEB_STATUS_REPORTS 
 Where WRES_ID_MGR = @p0 
   and WREPORT_IS_ENABLED <> 0 
 Order By WREPORT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectAllSRReqForResID TO MSProjectServerRole
GO



/* Query #10211 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllResourceForNameEvenDisabled
   @p0 NVARCHAR(255)
AS
--Select * From MSP_WEB_RESOURCES Where lower(RES_NAME)=lower(@p0) RETURN
Select * 
  From MSP_WEB_RESOURCES 
 Where lower(RES_NAME) = lower(@p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllResourceForNameEvenDisabled TO MSProjectServerRole
GO



/* Query #10212 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNewRespForSRID1
   @p0 INT
AS
--Select * From MSP_WEB_STATUS_RESPONSES Where WSR_ID=@p0 and WRESP_IS_NEW_RESPONSE<>0 and WSUBMIT_STATUS=2 RETURN
Select * 
  From MSP_WEB_STATUS_RESPONSES 
 Where WSR_ID = @p0 
   and WRESP_IS_NEW_RESPONSE <> 0 
   and WSUBMIT_STATUS = 2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNewRespForSRID1 TO MSProjectServerRole
GO



/* Query #10213 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetPartialTasksToNonPending
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Update MSP_WEB_ASSIGNMENTS set WASSN_DELEG_PENDING=0 where WRES_ID=@p0 and TASK_ID=@p1 and WPROJ_ID=@p2 RETURN(0)
Update MSP_WEB_ASSIGNMENTS 
   set WASSN_DELEG_PENDING = 0 
 where (WRES_ID = @p0 or WRES_ID = -1)
   and TASK_UID = @p1 
   and WPROJ_ID = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetPartialTasksToNonPending TO MSProjectServerRole
GO



/* Query #10214 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetResourceUpdateFlagForTeamStatusMsg
   @p0 INT,
   @p1 INT
AS
--Update MSP_WEB_ASSIGNMENTS set WASSN_RESOURCE_UPDATE=1 where WRES_ID_TEAM_LEAD=@p1 and WASSN_ID in (Select MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID From MSP_WEB_MESSAGES_ASSIGNMENTS Where WMSG_ID=@p0) RETURN(0)
Update MSP_WEB_ASSIGNMENTS 
   set WASSN_RESOURCE_UPDATE = 1 
 where WRES_ID_TEAM_LEAD = @p1 
   and WASSN_ID in (Select MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID 
                      From MSP_WEB_MESSAGES_ASSIGNMENTS 
                     Where WMSG_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetResourceUpdateFlagForTeamStatusMsg TO MSProjectServerRole
GO



/* Query #10215 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetActualsPendingFlagForTeamStatusMsg
   @p0 INT,
   @p1 INT
AS
--Update MSP_WEB_ASSIGNMENTS set WASSN_ACTUALS_PENDING=1 where WASSN_SEND_UPDATE_NEEDED<>0 and WRES_ID_TEAM_LEAD<>@p1 and WASSN_ID in (Select MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID From MSP_WEB_MESSAGES_ASSIGNMENTS Where WMSG_ID=@p0) RETURN(0)
Update MSP_WEB_ASSIGNMENTS 
   set WASSN_ACTUALS_PENDING = 1 
 where WASSN_SEND_UPDATE_NEEDED <> 0 
   and WRES_ID_TEAM_LEAD <> @p1 
   and WASSN_ID in (Select MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID 
                      From MSP_WEB_MESSAGES_ASSIGNMENTS 
                     Where WMSG_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetActualsPendingFlagForTeamStatusMsg TO MSProjectServerRole
GO



/* Query #10216 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllResourceForWindowsAccountEvenDisabled
   @p0 NVARCHAR(255)
AS
--Select * From MSP_WEB_RESOURCES Where lower(WRES_NT_ACCOUNT)=lower(@p0) RETURN
Select * 
  From MSP_WEB_RESOURCES 
 Where WRES_USE_NT_LOGON<>0 and lower(WRES_NT_ACCOUNT)=lower(@p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllResourceForWindowsAccountEvenDisabled TO MSProjectServerRole
GO



/* Query #10300 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEntResourceUIDandType
   @p0 INT
AS
--SELECT A.RES_TYPE, A.RES_UID, A.RES_NAME FROM MSP_RESOURCES A INNER JOIN MSP_PROJECTS B ON A.PROJ_ID = B.PROJ_ID WHERE (B.PROJ_TYPE = 3) AND (A.RES_UID =^0)
  Select A.RES_TYPE, A.RES_UID, A.RES_NAME
    From MSP_RESOURCES A INNER JOIN MSP_PROJECTS B ON A.PROJ_ID = B.PROJ_ID 
   Where (B.PROJ_TYPE = 3) AND (A.RES_UID = @p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEntResourceUIDandType TO MSProjectServerRole
GO


/* Query #10301 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEntResourceMINMAXTPDates
   @p0 INT
AS
--SELECT MIN(ResourceTimeStart) AS XMINDATE, MAX(ResourceTimeStart) AS XMAXDATE FROM MSP_VIEW_RES_TP_BY_DAY WHERE ResourceUniqueID = ^0
  Select MIN(ResourceTimeStart) as XMINDATE, MAX(ResourceTimeStart) as XMAXDATE 
    From MSP_VIEW_RES_TP_BY_DAY
   Where ResourceUniqueID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEntResourceMINMAXTPDates TO MSProjectServerRole
GO



/* Query #12001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectAllProjects
AS
Select * From MSP_WEB_PROJECTS RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectAllProjects TO MSProjectServerRole
GO



/* Query #13000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetLastAutonumber
AS
select @@IDENTITY as 'AutoNumber' RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetLastAutonumber TO MSProjectServerRole
GO



/* Query #13003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_OneAssnAgainstOneMgrRule
   @p0 INT,
   @p1 INT
AS
--Select DISTINCT WASSN_ID, MSP_WEB_MGR_RULES.WRULE_ID, MSP_WEB_MGR_RULES.WRES_ID_MGR, WRULE_TYPE, WRULE_CONDITION_TYPE FROM MSP_WEB_ASSIGNMENTS, MSP_WEB_MGR_RULES, MSP_WEB_MGR_RULES_LISTS WHERE WASSN_ID=@p0 AND MSP_WEB_MGR_RULES.WRULE_ID=@p1 AND MSP_WEB_MGR_RULES_LISTS.WRULE_ID=@p1 AND ((MSP_WEB_ASSIGNMENTS.WPROJ_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID<>0) OR (MSP_WEB_ASSIGNMENTS.WPROJ_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID=0)) AND  ((MSP_WEB_ASSIGNMENTS.WRES_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID<>0) OR (MSP_WEB_ASSIGNMENTS.WRES_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=1 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID=0)) RETURN
Select DISTINCT WASSN_ID, 
                MSP_WEB_MGR_RULES.WRULE_ID, 
                MSP_WEB_MGR_RULES.WRES_ID_MGR, 
                WRULE_TYPE, 
                WRULE_CONDITION_TYPE 
  FROM MSP_WEB_ASSIGNMENTS, 
       MSP_WEB_MGR_RULES, 
       MSP_WEB_MGR_RULES_LISTS 
 WHERE WASSN_ID = @p0 
   AND MSP_WEB_MGR_RULES.WRULE_ID = @p1 
   AND MSP_WEB_MGR_RULES_LISTS.WRULE_ID = @p1 
   AND ((MSP_WEB_ASSIGNMENTS.WPROJ_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
                                                FROM MSP_WEB_MGR_RULES_LISTS 
                                               WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE = 0 
                                                 AND MSP_WEB_MGR_RULES.WRULE_ID = MSP_WEB_MGR_RULES_LISTS.WRULE_ID) 
             AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID <> 0) 
            OR (MSP_WEB_ASSIGNMENTS.WPROJ_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
                                                   FROM MSP_WEB_MGR_RULES_LISTS 
                                                  WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE = 0 
                                                    AND MSP_WEB_MGR_RULES.WRULE_ID = MSP_WEB_MGR_RULES_LISTS.WRULE_ID) 
                   AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID = 0)) 
   AND ((MSP_WEB_ASSIGNMENTS.WRES_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
                                               FROM MSP_WEB_MGR_RULES_LISTS 
                                              WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE = 0 
                                                AND MSP_WEB_MGR_RULES.WRULE_ID = MSP_WEB_MGR_RULES_LISTS.WRULE_ID) 
             AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID <> 0) 
            OR (MSP_WEB_ASSIGNMENTS.WRES_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
                                                  FROM MSP_WEB_MGR_RULES_LISTS 
                                                 WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE = 1 
                                                   AND MSP_WEB_MGR_RULES.WRULE_ID = MSP_WEB_MGR_RULES_LISTS.WRULE_ID) 
                   AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID = 0))
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_OneAssnAgainstOneMgrRule TO MSProjectServerRole
GO



/* Query #13004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnFieldsFromAssnID
   @p0 INT
AS
--select TASK_NAME, ASSN_WORK, ASSN_REM_WORK, ASSN_START_DATE, ASSN_FINISH_DATE, WASSN_COMMENTS FROM MSP_WEB_ASSIGNMENTS WHERE WASSN_ID=@p0 RETURN
select TASK_NAME, 
       ASSN_WORK, 
       ASSN_REM_WORK, 
       ASSN_START_DATE, 
       ASSN_FINISH_DATE, 
       WASSN_COMMENTS 
  FROM MSP_WEB_ASSIGNMENTS 
 WHERE WASSN_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnFieldsFromAssnID TO MSProjectServerRole
GO



/* Query #13005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetOneCustomFieldFromAssnID
   @p0 INT,
   @p1 INT
AS
--select * FROM MSP_WEB_WORKGROUP_FIELDS WHERE WASSN_ID=@p0 AND FIELD_ID=@p1 RETURN
select * 
  FROM MSP_WEB_WORKGROUP_FIELDS 
 WHERE WASSN_ID = @p0 
   AND FIELD_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetOneCustomFieldFromAssnID TO MSProjectServerRole
GO



/* Query #13006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMgrRulesFromMgrID
   @p0 INT
AS
--select * FROM MSP_WEB_MGR_RULES where WRES_ID_MGR=@p0 order by WRULE_NAME RETURN
select * 
  FROM MSP_WEB_MGR_RULES 
 where WRES_ID_MGR = @p0 
 order by WRULE_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMgrRulesFromMgrID TO MSProjectServerRole
GO



/* Query #13007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCFields
   @p0 INT
AS
--select distinct CUSTFIELD_NAME, CUSTFIELD_TYPE, MSP_WEB_WORKGROUP_FIELDS_INFO.FIELD_ID FROM MSP_WEB_WORKGROUP_FIELDS_INFO, MSP_WEB_WORKGROUP_FIELDS WHERE MSP_WEB_WORKGROUP_FIELDS_INFO.FIELD_ID=MSP_WEB_WORKGROUP_FIELDS.FIELD_ID order by CUSTFIELD_NAME RETURN
-- Conversion to ANSI INNER JOIN
select distinct CONV_STRING as CUSTFIELD_NAME, 
                CUSTFIELD_TYPE, 
                MSP_WEB_WORKGROUP_FIELDS_INFO.FIELD_ID 
  FROM MSP_WEB_WORKGROUP_FIELDS_INFO 
       INNER JOIN MSP_WEB_WORKGROUP_FIELDS ON MSP_WEB_WORKGROUP_FIELDS_INFO.FIELD_ID=MSP_WEB_WORKGROUP_FIELDS.FIELD_ID
       INNER JOIN MSP_WEB_CONVERSIONS ON MSP_WEB_WORKGROUP_FIELDS_INFO.CONV_VALUE=MSP_WEB_CONVERSIONS.CONV_VALUE 
 WHERE MSP_WEB_WORKGROUP_FIELDS_INFO.CONV_VALUE>0 and LANG_ID=@p0
 order by CUSTFIELD_NAME

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCFields TO MSProjectServerRole
GO



/* Query #13008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectProjectsForRuleID
   @p0 INT
AS
--select ITEM_ID, PROJ_NAME  from MSP_WEB_MGR_RULES_LISTS, MSP_WEB_PROJECTS WHERE WRULE_ID=@p0 AND ITEM_TYPE=0 and ITEM_ID=WPROJ_ID RETURN
select ITEM_ID, 
       PROJ_NAME 
  from MSP_WEB_MGR_RULES_LISTS, 
       MSP_WEB_PROJECTS 
 WHERE WRULE_ID = @p0 
   AND ITEM_TYPE = 0 
   and ITEM_ID = WPROJ_ID
 ORDER BY PROJ_NAME, WPROJ_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectProjectsForRuleID TO MSProjectServerRole
GO



/* Query #13009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectAllResources
AS
--select WRES_ID, RES_NAME from MSP_WEB_RESOURCES where WRES_IS_ENABLED<>0 RETURN
select WRES_ID, 
       RES_NAME 
  from MSP_WEB_RESOURCES 
 where WRES_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectAllResources TO MSProjectServerRole
GO



/* Query #13010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectResourcesForRuleID
   @p0 INT
AS
--select ITEM_ID, RES_NAME from MSP_WEB_MGR_RULES_LISTS, MSP_WEB_RESOURCES WHERE WRES_IS_ENABLED<>0 and WRULE_ID=@p0 AND ITEM_TYPE=1 and ITEM_ID=WRES_ID RETURN
select ITEM_ID, 
       RES_NAME 
  from MSP_WEB_MGR_RULES_LISTS, 
       MSP_WEB_RESOURCES 
 WHERE WRES_IS_ENABLED <> 0 
   and WRULE_ID = @p0 
   AND ITEM_TYPE = 1 
   and ITEM_ID = WRES_ID
 ORDER BY RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectResourcesForRuleID TO MSProjectServerRole
GO



/* Query #13011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectARuleForRuleID
   @p0 INT
AS
--select * from MSP_WEB_MGR_RULES WHERE WRULE_ID=@p0 RETURN
select * 
  from MSP_WEB_MGR_RULES 
 WHERE WRULE_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectARuleForRuleID TO MSProjectServerRole
GO



/* Query #13012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteListItemsForRuleID
   @p0 INT
AS
--Delete from MSP_WEB_MGR_RULES_LISTS Where WRULE_ID=@p0 RETURN(0)
Delete 
  from MSP_WEB_MGR_RULES_LISTS 
 Where WRULE_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteListItemsForRuleID TO MSProjectServerRole
GO



/* Query #13013 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectListItemsForRuleID
   @p0 INT
AS
--select * from MSP_WEB_MGR_RULES_LISTS where WRULE_ID=@p0 RETURN
select * 
  from MSP_WEB_MGR_RULES_LISTS 
 where WRULE_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectListItemsForRuleID TO MSProjectServerRole
GO



/* Query #13014 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteARuleForRuleID
   @p0 INT
AS
--Delete from MSP_WEB_MGR_RULES where WRULE_ID=@p0 RETURN(0)
Delete 
  from MSP_WEB_MGR_RULES 
 where WRULE_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteARuleForRuleID TO MSProjectServerRole
GO



/* Query #13016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectDelegToResourcesForRuleID
   @p0 INT
AS
--select ITEM_ID, RES_NAME from MSP_WEB_MGR_RULES_LISTS, MSP_WEB_RESOURCES WHERE WRES_IS_ENABLED<>0 and WRULE_ID=@p0 AND ITEM_TYPE=2 and ITEM_ID=WRES_ID RETURN
select ITEM_ID, 
       RES_NAME 
  from MSP_WEB_MGR_RULES_LISTS, 
       MSP_WEB_RESOURCES 
 WHERE WRES_IS_ENABLED <> 0 
   and WRULE_ID = @p0 
   AND ITEM_TYPE = 2 
   and ITEM_ID = WRES_ID
 ORDER BY RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectDelegToResourcesForRuleID TO MSProjectServerRole
GO



/* Query #13017 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyAssignment
AS
--select * from MSP_WEB_ASSIGNMENTS WHERE WASSN_ID = -1 RETURN
select * 
  from MSP_WEB_ASSIGNMENTS WITH (READPAST) 
 WHERE WASSN_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyAssignment TO MSProjectServerRole
GO



/* Query #13018 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllNonworkingNames
AS
--SELECT * FROM MSP_WEB_NONWORKING_CATEGORIES ORDER BY WNWRK_ORDER RETURN
SELECT * 
  FROM MSP_WEB_NONWORKING_CATEGORIES 
 ORDER BY WNWRK_ORDER
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllNonworkingNames TO MSProjectServerRole
GO



/* Query #13019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyWork
AS
--SELECT * FROM MSP_WEB_WORK WHERE WRES_ID = -1 RETURN
SELECT * 
  FROM MSP_WEB_WORK WITH (READPAST) 
 WHERE WRES_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyWork TO MSProjectServerRole
GO



/* Query #13020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSortedActualWorkFromAssnID
   @p0 INT
AS
--select * from MSP_WEB_WORK WHERE WASSN_ID = @p0 and WWORK_TYPE=1 order by WWORK_START RETURN
select * 
  from MSP_WEB_WORK 
 WHERE WASSN_ID = @p0 
   and WWORK_TYPE = 1 
 order by WWORK_START
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSortedActualWorkFromAssnID TO MSProjectServerRole
GO



/* Query #13021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectsForOwner
   @p0 INT
AS
--select * from MSP_WEB_PROJECTS where WRES_ID = @p0 order by PROJ_NAME RETURN
select * 
  from MSP_WEB_PROJECTS 
 where WRES_ID = @p0 or 
       WPROJ_ID in (select distinct WPROJ_ID from MSP_WEB_ASSIGNMENTS where WRES_ID_MGR=@p0)
 order by PROJ_NAME, WPROJ_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectsForOwner TO MSProjectServerRole
GO



/* Query #13022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSubTasks
   @p0 INT
AS

SELECT TaskUniqueID as TASK_UID, TaskName as TASK_NAME
FROM MSP_VIEW_PROJ_TASKS_STD VPS
WHERE VPS.WPROJ_ID=@p0 and TaskSummary<>0 and TaskUniqueID>0
ORDER BY TaskID

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSubTasks TO MSProjectServerRole
GO



/* Query #13023 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllMgrs
AS
--select R.* from MSP_WEB_RESOURCES R,MSP_WEB_SECURITY_GROUP_MEMBERS SGM,MSP_WEB_SECURITY_GROUPS SG where R.WRES_IS_ENABLED <> 0 and R.WRES_GUID=SGM.WRES_GUID and SGM.WSEC_GRP_GUID=SG.WSEC_GRP_GUID and SG.WSEC_GRP_ID=4 RETURN
select R.*
  from MSP_WEB_RESOURCES R,
       MSP_WEB_SECURITY_GROUP_MEMBERS SGM,
       MSP_WEB_SECURITY_GROUPS SG
 where R.WRES_IS_ENABLED <> 0
   and R.WRES_GUID=SGM.WRES_GUID 
   and SGM.WSEC_GRP_GUID=SG.WSEC_GRP_GUID
   and SG.WSEC_GRP_ID=4
RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllMgrs TO MSProjectServerRole
GO



/* Query #13024 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyMsg
AS
--select * from MSP_WEB_MESSAGES where WMSG_ID = -1 RETURN
select * 
  from MSP_WEB_MESSAGES WITH (READPAST) 
 where WMSG_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyMsg TO MSProjectServerRole
GO



/* Query #13025 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyNonworking
AS
--select * from MSP_WEB_NONWORKING where WNONWORK_ID = -1 RETURN
select * 
  from MSP_WEB_NONWORKING WITH (READPAST) 
 where WNONWORK_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyNonworking TO MSProjectServerRole
GO



/* Query #13026 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyMsgNonworking
AS
--select * from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID = -1 RETURN
select * 
  from MSP_WEB_MESSAGES_NONWORKING WITH (READPAST) 
 where WMSG_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyMsgNonworking TO MSProjectServerRole
GO



/* Query #13027 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNonworkingFile
AS
--select WPROJ_ID from MSP_WEB_PROJECTS WHERE WPROJ_IS_NONWORKING<>0 RETURN
select WPROJ_ID 
  from MSP_WEB_PROJECTS 
 WHERE WPROJ_IS_NONWORKING <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNonworkingFile TO MSProjectServerRole
GO



/* Query #13028 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingFromMsgId
   @p0 INT
AS
--DELETE FROM MSP_WEB_MESSAGES_NONWORKING WHERE WMSG_ID=@p0 RETURN(0)
DELETE 
  FROM MSP_WEB_MESSAGES_NONWORKING 
 WHERE WMSG_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingFromMsgId TO MSProjectServerRole
GO



/* Query #13029 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingFromMsgId
   @p0 INT
AS
--delete from MSP_WEB_NONWORKING where WNONWORK_ID IN (SELECT WNONWORK_ID FROM MSP_WEB_MESSAGES_NONWORKING WHERE WMSG_ID = @p0) RETURN(0)
delete 
  from MSP_WEB_NONWORKING 
 where WNONWORK_ID IN (SELECT WNONWORK_ID 
                         FROM MSP_WEB_MESSAGES_NONWORKING 
                        WHERE WMSG_ID = @p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingFromMsgId TO MSProjectServerRole
GO



/* Query #13030 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyNonworkingCategory
AS
--select * from MSP_WEB_NONWORKING_CATEGORIES where WNWRK_ID = -1 RETURN
select * 
  from MSP_WEB_NONWORKING_CATEGORIES WITH (READPAST) 
 where WNWRK_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyNonworkingCategory TO MSProjectServerRole
GO



/* Query #13032 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMgrEnabledRulesFromMgrID
   @p0 INT
AS
--select * FROM MSP_WEB_MGR_RULES where WRES_ID_MGR=@p0 and WRULE_IS_ENABLED<>0 RETURN
select * 
  FROM MSP_WEB_MGR_RULES 
 where WRES_ID_MGR = @p0 
   and WRULE_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMgrEnabledRulesFromMgrID TO MSProjectServerRole
GO



/* Query #13033 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectRevertedProjectsForRuleID
   @p0 INT,
   @p1 INT
AS
--select * from MSP_WEB_PROJECTS where WRES_ID = @p1 and WPROJ_ID not in (select ITEM_ID from MSP_WEB_MGR_RULES_LISTS, MSP_WEB_PROJECTS WHERE WRULE_ID=@p0 AND ITEM_TYPE=0 and ITEM_ID=WPROJ_ID) order by PROJ_NAME RETURN
select * 
  from MSP_WEB_PROJECTS 
 where WRES_ID = @p1 
   and WPROJ_ID not in (select ITEM_ID 
                          from MSP_WEB_MGR_RULES_LISTS, 
                               MSP_WEB_PROJECTS 
                         WHERE WRULE_ID = @p0 
                           AND ITEM_TYPE = 0 
                           and ITEM_ID = WPROJ_ID) 
 order by PROJ_NAME, WPROJ_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectRevertedProjectsForRuleID TO MSProjectServerRole
GO



/* Query #13034 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectRevertedResourcesForRuleID
   @p0 INT
AS
--select WRES_ID, RES_NAME from MSP_WEB_RESOURCES where WRES_IS_ENABLED<>0 and WRES_ID not in (select ITEM_ID from MSP_WEB_MGR_RULES_LISTS, MSP_WEB_RESOURCES WHERE WRES_IS_ENABLED<>0 and WRULE_ID=@p0 AND ITEM_TYPE=1 and ITEM_ID=WRES_ID) RETURN
select WRES_ID, 
       RES_NAME 
  from MSP_WEB_RESOURCES 
 where WRES_IS_ENABLED <> 0 
   and WRES_ID not in (select ITEM_ID 
                         from MSP_WEB_MGR_RULES_LISTS, 
                              MSP_WEB_RESOURCES 
                        WHERE WRES_IS_ENABLED <> 0 
                          and WRULE_ID = @p0 
                          AND ITEM_TYPE = 1 
                          and ITEM_ID = WRES_ID)
  ORDER BY RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectRevertedResourcesForRuleID TO MSProjectServerRole
GO



/* Query #13035 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectARuleForRuleName
   @p0 INT,
   @p1 NVARCHAR(255)
AS
--select * from MSP_WEB_MGR_RULES WHERE WRES_ID_MGR=@p0 AND lower(WRULE_NAME)=lower(@p1) RETURN
select * 
  from MSP_WEB_MGR_RULES 
 WHERE WRES_ID_MGR = @p0 
   AND lower(WRULE_NAME) = lower(@p1)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectARuleForRuleName TO MSProjectServerRole
GO



/* Query #13036 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllLinks
AS
--select * from MSP_WEB_ADMIN_LINKS WHERE WLINKS_TYPE=0 RETURN
select * 
  from MSP_WEB_ADMIN_LINKS 
 WHERE WLINKS_TYPE = 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllLinks TO MSProjectServerRole
GO



/* Query #13037 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllContents
AS
--select * from MSP_WEB_ADMIN_LINKS WHERE WLINKS_TYPE=1 RETURN
select * 
  from MSP_WEB_ADMIN_LINKS 
 WHERE WLINKS_TYPE = 1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllContents TO MSProjectServerRole
GO


/* Query #13038 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SelectRevertedDelegToResourcesForRuleID
   @p0 INT
AS
select WRES_ID,  RES_NAME 
from MSP_WEB_RESOURCES 
WHERE WRES_IS_ENABLED <> 0 
and WRES_ID not in 
(select ITEM_ID 
  from MSP_WEB_MGR_RULES_LISTS, 
       MSP_WEB_RESOURCES 
 WHERE WRES_IS_ENABLED <> 0 
   and WRULE_ID = @p0 
   AND ITEM_TYPE = 2 
   and ITEM_ID = WRES_ID)
 ORDER BY RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SelectRevertedDelegToResourcesForRuleID TO MSProjectServerRole
GO


/* Query #15000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSummaryTasksForResID
   @p0 INT
AS
--select * from MSP_WEB_ASSIGNMENTS where TASK_IS_SUMMARY<>0 and WRES_ID=@p0 RETURN
select * 
  from MSP_WEB_ASSIGNMENTS 
 where TASK_IS_SUMMARY <> 0 
   and WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSummaryTasksForResID TO MSProjectServerRole
GO



/* Query #15010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetResourceOffline
   @p0 INT
AS
--update MSP_WEB_RESOURCES set WRES_IS_OFFLINE=1 where WRES_ID=@p0 and WRES_IS_ENABLED<>0 RETURN(0)
update MSP_WEB_RESOURCES 
   set WRES_IS_OFFLINE = 1 
 where WRES_ID = @p0 
   and WRES_IS_ENABLED <> 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetResourceOffline TO MSProjectServerRole
GO



/* Query #15011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetResourceOnline
   @p0 INT
AS
--update MSP_WEB_RESOURCES set WRES_IS_OFFLINE=0 where WRES_ID=@p0 and WRES_IS_ENABLED<>0 RETURN(0)
update MSP_WEB_RESOURCES 
   set WRES_IS_OFFLINE = 0 
 where WRES_ID = @p0 
   and WRES_IS_ENABLED <> 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetResourceOnline TO MSProjectServerRole
GO



/* Query #15012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetOfflineFlagForResID
   @p0 INT
AS
--select WRES_IS_OFFLINE from MSP_WEB_RESOURCES where WRES_ID=@p0 and WRES_IS_ENABLED<>0 RETURN
select WRES_IS_OFFLINE 
  from MSP_WEB_RESOURCES 
 where WRES_ID = @p0 
   and WRES_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetOfflineFlagForResID TO MSProjectServerRole
GO



/* Query #15099 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_InListQuery_GetCFInfoID2
   @p1 INT
AS
--SELECT DISTINCT PWI.CUSTFIELD_INFO_ID FROM MSP_WEB_PROJECT_WORKGROUP_INFO PWI,MSP_WEB_ASSIGNMENTS WA Where PWI.WPROJ_ID=WA.WPROJ_ID and (WA.WRES_ID=@p1 OR WA.WRES_ID_MGR=@p1) RETURN
--Conversion to ANSI INNER JOIN
SELECT DISTINCT PWI.CUSTFIELD_INFO_ID 
  FROM MSP_WEB_PROJECT_WORKGROUP_INFO PWI 
       INNER JOIN MSP_WEB_ASSIGNMENTS WA 
          ON PWI.WPROJ_ID = WA.WPROJ_ID 
 Where (WA.WRES_ID = @p1 
            OR WA.WRES_ID_MGR = @p1)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_InListQuery_GetCFInfoID2 TO MSProjectServerRole
GO



/* Query #16000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllGanttSchemes
AS
--Select * From MSP_WEB_GANTT_SCHEMES Order By WGANTT_SCHEME_ID RETURN
Select * 
  From MSP_WEB_GANTT_SCHEMES 
 Order By WGANTT_SCHEME_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllGanttSchemes TO MSProjectServerRole
GO



/* Query #16001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetGanttSettingsForScheme
   @p0 INT
AS
--Select * From MSP_WEB_GANTT_SETTINGS Where WGANTT_SCHEME_ID=@p0 RETURN
Select * 
  From MSP_WEB_GANTT_SETTINGS 
 Where WGANTT_SCHEME_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetGanttSettingsForScheme TO MSProjectServerRole
GO



/* Query #16002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminInfoForResId
   @p0 INT
AS
--Select WRES_ID, RESERVED_DATA3, RESERVED_DATA4 From MSP_WEB_RESOURCES Where WRES_IS_ENABLED<>0 and WRES_ID=@p0 and WRES_IS_ADMIN<>0 RETURN
Select WRES_ID, 
       RESERVED_DATA3, 
       RESERVED_DATA4 
  From MSP_WEB_RESOURCES 
 Where WRES_IS_ENABLED <> 0 
   and WRES_ID = @p0 
   and WRES_IS_ADMIN <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminInfoForResId TO MSProjectServerRole
GO



/* Query #16008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectsForViewResProjID
   @p0 INT
AS
Select MSP_WEB_PROJECTS.*,
       WDSN_NAME,
       WDSN_LOGIN_ID,
       WDSN_PASSWORD 
  From MSP_WEB_PROJECTS 
       LEFT JOIN MSP_WEB_VIEW_DSNS ON MSP_WEB_PROJECTS.WDSN_ID=MSP_WEB_VIEW_DSNS.WDSN_ID 
 Where MSP_WEB_PROJECTS.WPROJ_ID=@p0 

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectsForViewResProjID TO MSProjectServerRole
GO

/* Query #16009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ProjectViewMainFieldList
   @p0 INT,
   @p1 INT
AS
--Select MSP_WEB_VIEW_FIELDS.WFIELD_ID, WFIELD_NAME_OLEDB, WFIELD_NAME_SQL, MSP_WEB_WORKGROUP_FIELDS.INDICATOR_VAL FROM (((MSP_WEB_VIEW_REPORTS_FIELDS INNER JOIN MSP_WEB_VIEW_REPORTS ON MSP_WEB_VIEW_REPORTS_FIELDS.WVIEW_ID = MSP_WEB_VIEW_REPORTS.WVIEW_ID) INNER JOIN MSP_WEB_VIEW_FIELDS ON MSP_WEB_VIEW_REPORTS_FIELDS.WFIELD_ID = MSP_WEB_VIEW_FIELDS.WFIELD_ID) LEFT JOIN MSP_WEB_WORKGROUP_FIELDS ON MSP_WEB_VIEW_FIELDS.WFIELD_ID = MSP_WEB_WORKGROUP_FIELDS.FIELD_ID) LEFT JOIN MSP_WEB_ASSIGNMENTS ON MSP_WEB_WORKGROUP_FIELDS.WASSN_ID = MSP_WEB_ASSIGNMENTS.WASSN_ID WHERE MSP_WEB_VIEW_REPORTS.WVIEW_ID=@p0 and WFIELD_IN_PROJECT_VIEW<>0 AND WFIELD_IS_GANTT_DEFAULT=0 AND ((MSP_WEB_ASSIGNMENTS.TASK_UID Is Null and MSP_WEB_WORKGROUP_FIELDS.WASSN_ID Is Null) Or (MSP_WEB_ASSIGNMENTS.TASK_UID=0 AND MSP_WEB_ASSIGNMENTS.WPROJ_ID=@p1)) RETURN
Select MSP_WEB_VIEW_FIELDS.WFIELD_ID, 
       WFIELD_NAME_OLEDB, 
       WFIELD_NAME_SQL, 
       MSP_WEB_WORKGROUP_FIELDS.INDICATOR_VAL 
  FROM (((MSP_WEB_VIEW_REPORTS_FIELDS 
       INNER JOIN MSP_WEB_VIEW_REPORTS 
          ON MSP_WEB_VIEW_REPORTS_FIELDS.WVIEW_ID = MSP_WEB_VIEW_REPORTS.WVIEW_ID) 
       INNER JOIN MSP_WEB_VIEW_FIELDS 
          ON MSP_WEB_VIEW_REPORTS_FIELDS.WFIELD_ID = MSP_WEB_VIEW_FIELDS.WFIELD_ID) 
       LEFT JOIN MSP_WEB_WORKGROUP_FIELDS 
         ON MSP_WEB_VIEW_FIELDS.WFIELD_ID = MSP_WEB_WORKGROUP_FIELDS.FIELD_ID) 
       LEFT JOIN MSP_WEB_ASSIGNMENTS 
         ON MSP_WEB_WORKGROUP_FIELDS.WASSN_ID = MSP_WEB_ASSIGNMENTS.WASSN_ID 
 WHERE MSP_WEB_VIEW_REPORTS.WVIEW_ID = @p0 
   and WFIELD_IN_PROJECT_VIEW <> 0 
   AND WFIELD_IS_GANTT_DEFAULT = 0 
   AND ((MSP_WEB_ASSIGNMENTS.TASK_UID Is Null 
             and MSP_WEB_WORKGROUP_FIELDS.WASSN_ID Is Null) 
            Or (MSP_WEB_ASSIGNMENTS.TASK_UID = 0 
                   AND MSP_WEB_ASSIGNMENTS.WPROJ_ID = @p1))
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ProjectViewMainFieldList TO MSProjectServerRole
GO

/* Query #16010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_TimesheetViewFieldList
   @p0 INT,
   @p1 INT
AS
SELECT VF.WFIELD_ID,
       WC.CONV_STRING,
       WFIELD_NAME_SQL,
       WFIELD_TEXTCONV_TYPE,
       WFIELD_IS_CUSTOM_FIELD,
       WFI.CUSTFIELD_INFO_ID,
       VRF.WVIEW_FIELD_WIDTH,
       VRF.WVIEW_FIELD_AUTOSIZE,
       ((CASE WHEN CUSTFIELD_NAME is null OR CUSTFIELD_NAME=N'' THEN WC2.CONV_STRING ELSE CUSTFIELD_NAME END)) as CUSTFIELD_NAME
  FROM MSP_WEB_VIEW_REPORTS VR 
       INNER JOIN MSP_WEB_VIEW_REPORTS_FIELDS VRF ON VR.WVIEW_ID=VRF.WVIEW_ID
       INNER JOIN MSP_WEB_VIEW_FIELDS VF ON VRF.WFIELD_ID=VF.WFIELD_ID 
       INNER JOIN MSP_WEB_CONVERSIONS WC ON VF.WFIELD_NAME_CONV_VALUE=WC.CONV_VALUE 
       LEFT JOIN MSP_WEB_WORKGROUP_FIELDS_INFO WFI ON VF.WFIELD_ID=WFI.FIELD_ID 
       LEFT JOIN MSP_WEB_CONVERSIONS WC2 ON (WFI.CONV_VALUE=WC2.CONV_VALUE and WC2.LANG_ID=@p1) 
 WHERE VR.WVIEW_ID=99
   and WC.LANG_ID=@p1
   and ( WFI.CUSTFIELD_INFO_ID Is Null 
         or WFI.CUSTFIELD_INFO_ID in 
            (
              SELECT DISTINCT PWI.CUSTFIELD_INFO_ID 
                FROM MSP_WEB_ASSIGNMENTS WA, 
                     MSP_WEB_PROJECT_WORKGROUP_INFO PWI
               WHERE WA.WRES_ID = @p0 
                 and WA.WPROJ_ID=PWI.WPROJ_ID
            )
       ) 
 ORDER BY VRF.WVIEW_FIELD_ORDER
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_TimesheetViewFieldList TO MSProjectServerRole
GO

/* Query #16011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ProjectViewAllFieldList
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT
AS
BEGIN
   declare @ent_global_proj_id int
   select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

   SELECT (CASE WHEN MAS.AS_ID is null THEN WC.CONV_STRING ELSE AS_VALUE END) as CONV_STRING,
          WFIELD_NAME_OLEDB,
          WFIELD_TEXTCONV_TYPE,
          WFIELD_IS_CUSTOM_FIELD,
          MSP_WEB_VIEW_FIELDS.WFIELD_ID, 
          MSP_WEB_WORKGROUP_FIELDS.INDICATOR_VAL,
          MSP_WEB_VIEW_REPORTS_FIELDS.WVIEW_FIELD_WIDTH,
          MSP_WEB_VIEW_REPORTS_FIELDS.WVIEW_FIELD_AUTOSIZE,
          (CASE WHEN WWFI.CUSTFIELD_NAME is null OR WWFI.CUSTFIELD_NAME=N'' 
                 THEN WC2.CONV_STRING 
                 ELSE WWFI.CUSTFIELD_NAME END) as CUSTFIELD_NAME
     FROM MSP_WEB_VIEW_REPORTS_FIELDS INNER JOIN MSP_WEB_VIEW_REPORTS ON MSP_WEB_VIEW_REPORTS_FIELDS.WVIEW_ID=MSP_WEB_VIEW_REPORTS.WVIEW_ID
          INNER JOIN MSP_WEB_VIEW_FIELDS ON MSP_WEB_VIEW_REPORTS_FIELDS.WFIELD_ID=MSP_WEB_VIEW_FIELDS.WFIELD_ID
          INNER JOIN MSP_WEB_CONVERSIONS WC ON MSP_WEB_VIEW_FIELDS.WFIELD_NAME_CONV_VALUE=WC.CONV_VALUE
          LEFT JOIN MSP_WEB_WORKGROUP_FIELDS ON MSP_WEB_VIEW_FIELDS.WFIELD_ID=MSP_WEB_WORKGROUP_FIELDS.FIELD_ID
          LEFT JOIN MSP_WEB_ASSIGNMENTS ON MSP_WEB_WORKGROUP_FIELDS.WASSN_ID=MSP_WEB_ASSIGNMENTS.WASSN_ID
          LEFT JOIN MSP_WEB_PROJECT_WORKGROUP_INFO WPWI ON MSP_WEB_ASSIGNMENTS.WPROJ_ID=WPWI.WPROJ_ID
          LEFT JOIN MSP_WEB_WORKGROUP_FIELDS_INFO WWFI ON WPWI.CUSTFIELD_INFO_ID=WWFI.CUSTFIELD_INFO_ID 
          LEFT JOIN MSP_WEB_CONVERSIONS WC2 ON (WWFI.CONV_VALUE=WC2.CONV_VALUE and WC2.LANG_ID=@p3)
          LEFT JOIN MSP_FIELD_ATTRIBUTES MFA on (MSP_WEB_VIEW_FIELDS.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
          LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
    WHERE MSP_WEB_VIEW_REPORTS.WVIEW_ID=@p0 and WC.LANG_ID=@p3 and MSP_WEB_VIEW_FIELDS.WFIELD_IN_PROJECT_VIEW<>0 AND 
          (   (MSP_WEB_ASSIGNMENTS.TASK_UID Is Null and 
               MSP_WEB_WORKGROUP_FIELDS.WASSN_ID Is Null and 
               WWFI.FIELD_ID Is Null) 
           Or (MSP_WEB_ASSIGNMENTS.TASK_UID=0 AND 
               MSP_WEB_ASSIGNMENTS.WPROJ_ID=@p2 AND 
               MSP_WEB_WORKGROUP_FIELDS.FIELD_ID=WWFI.FIELD_ID)   ) 
   Order By WVIEW_FIELD_ORDER 

RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ProjectViewAllFieldList TO MSProjectServerRole
GO



/* Query #16013 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetTimesheetViewFieldList
   @p0 INT
AS
SELECT VF.WFIELD_ID,VRF.WVIEW_FIELD_WIDTH,VRF.WVIEW_FIELD_AUTOSIZE,CV.CONV_STRING,VRF.WVIEW_FIELD_ORDER FROM MSP_WEB_VIEW_REPORTS_FIELDS VRF, MSP_WEB_VIEW_FIELDS VF, MSP_WEB_CONVERSIONS CV WHERE VRF.WVIEW_ID = 99 and VRF.WFIELD_ID = VF.WFIELD_ID and VF.WFIELD_NAME_CONV_VALUE = CV.CONV_VALUE and CV.LANG_ID = @p0 ORDER BY CV.CONV_STRING RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetTimesheetViewFieldList TO MSProjectServerRole
GO



/* Query #16014 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllPortfolioFieldsForNewViews
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and VF.WFIELD_IN_PORTFOLIO_VIEW<>0)
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   Where not VF.WFIELD_ID in (1048, 2050, 2122)
   Order By CV.CONV_STRING
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllPortfolioFieldsForNewViews TO MSProjectServerRole
GO



/* Query #16015 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllWebclientFieldsForNewViews
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and VF.WFIELD_IN_WEBCLIENT_VIEW<>0)
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   Where not VF.WFIELD_ID in (1022, 2050, 2122)
   Order By CV.CONV_STRING
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllWebclientFieldsForNewViews TO MSProjectServerRole
GO



/* Query #16016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllTableInfo
AS
--Select * From MSP_WEB_VIEW_TABLES Order By WTABLE_ID RETURN
Select * 
  From MSP_WEB_VIEW_TABLES 
 Order By WTABLE_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllTableInfo TO MSProjectServerRole
GO



/* Query #16017 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetViewReportsForViewID
   @p0 INT
AS
--Select * From MSP_WEB_VIEW_REPORTS Where WVIEW_ID=@p0 RETURN
Select * 
  From MSP_WEB_VIEW_REPORTS 
 Where WVIEW_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetViewReportsForViewID TO MSProjectServerRole
GO



/* Query #16019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteViewReportsFieldsForViewID
   @p0 INT
AS
--Delete From MSP_WEB_VIEW_REPORTS_FIELDS Where WVIEW_ID=@p0 RETURN(0)
Delete 
  From MSP_WEB_VIEW_REPORTS_FIELDS 
 Where WVIEW_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteViewReportsFieldsForViewID TO MSProjectServerRole
GO



/* Query #16020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllProjects
AS
--Select WPROJ_ID,PROJ_NAME From MSP_WEB_PROJECTS Order By PROJ_NAME RETURN
Select WPROJ_ID, 
       PROJ_NAME 
  From MSP_WEB_PROJECTS 
 Where WPROJ_TYPE<3 and WPROJ_DEFAULT_WPROJ_ID=WPROJ_ID
 Order By PROJ_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllProjects TO MSProjectServerRole
GO



/* Query #16021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllViewsForViewType
   @p0 INT
AS
--Select WVIEW_ID,WVIEW_NAME,WVIEW_REPORT_KIND From MSP_WEB_VIEW_REPORTS Where WVIEW_TYPE=@p0 Order By WVIEW_NAME RETURN
Select WVIEW_ID, 
       WVIEW_NAME, 
       WVIEW_REPORT_KIND 
  From MSP_WEB_VIEW_REPORTS 
 Where WVIEW_TYPE = @p0 
 Order By WVIEW_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllViewsForViewType TO MSProjectServerRole
GO



/* Query #16028 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllCategories
AS
--select WSEC_CAT_ID, WSEC_CAT_NAME from MSP_WEB_SECURITY_CATEGORIES order by WSEC_CAT_NAME
Select WSEC_CAT_ID, 
       WSEC_CAT_NAME 
  From MSP_WEB_SECURITY_CATEGORIES 
 Order by WSEC_CAT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllCategories TO MSProjectServerRole
GO



/* Query #16029 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetViewsResourceForResID
   @p0 INT
AS
--Select WRES_ID,WRES_INCL_TEAMASSIGN_RESOURCES From MSP_WEB_RESOURCES Where WRES_ID=@p0 RETURN
Select WRES_ID, 
       WRES_INCL_TEAMASSIGN_RESOURCES 
  From MSP_WEB_RESOURCES 
 Where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetViewsResourceForResID TO MSProjectServerRole
GO



/* Query #16035 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDSNforDSNID
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT
AS
--Select * From MSP_WEB_VIEW_DSNS Where WDSN_ID=@p0 and exists (Select WRES_ID from MSP_WEB_RESOURCES Where WRES_ID=@p1 and RESERVED_DATA3=@p2 and RESERVED_DATA4=@p3) RETURN
Select * 
  From MSP_WEB_VIEW_DSNS 
 Where WDSN_ID = @p0 
   and exists (Select WRES_ID 
                 from MSP_WEB_RESOURCES 
                Where WRES_ID = @p1 
                  and RESERVED_DATA3 = @p2 
                  and RESERVED_DATA4 = @p3)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDSNforDSNID TO MSProjectServerRole
GO



/* Query #16037 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllNonNormalViewsForType
   @p0 INT
AS
--Select * From MSP_WEB_VIEW_REPORTS Where WVIEW_REPORT_KIND<>0 and WVIEW_TYPE=@p0 RETURN
Select * 
  From MSP_WEB_VIEW_REPORTS 
 Where WVIEW_REPORT_KIND <> 0 
   and WVIEW_TYPE = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllNonNormalViewsForType TO MSProjectServerRole
GO



/* Query #16038 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteViewReportCatForViewID
   @p0 INT
AS
--Delete From MSP_WEB_SECURITY_CATEGORY_OBJECTS Where WSEC_OBJ_TYPE=3 and WSEC_OBJ_ID=@p0 
Delete 
  From MSP_WEB_SECURITY_CATEGORY_OBJECTS
 Where WSEC_OBJ_TYPE=3 
   and WSEC_OBJ_ID=@p0 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteViewReportCatForViewID TO MSProjectServerRole
GO



/* Query #16039 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteViewReportsForViewID
   @p0 INT
AS
--Delete From MSP_WEB_VIEW_REPORTS Where WVIEW_ID=@p0 RETURN(0)
Delete 
  From MSP_WEB_VIEW_REPORTS 
 Where WVIEW_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteViewReportsForViewID TO MSProjectServerRole
GO



/* Query #16042 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetVisibleGanttStyles
   @p0 INT
AS
--Select WGANTT_STYLE_ID From MSP_WEB_GANTT_SETTINGS Where WGANTT_SCHEME_ID=@p0 and WGANTT_SHOW<>0 RETURN
Select WGANTT_STYLE_ID 
  From MSP_WEB_GANTT_SETTINGS 
 Where WGANTT_SCHEME_ID = @p0 
   and WGANTT_SHOW <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetVisibleGanttStyles TO MSProjectServerRole
GO



/* Query #16043 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectViewInfoForViewResProjID
   @p0 INT
AS
Select VT.*,
       VR.* 
  From MSP_WEB_VIEW_TABLES VT 
       INNER JOIN MSP_WEB_VIEW_REPORTS VR ON VT.WTABLE_ID=VR.WTABLE_ID 
 WHERE VR.WVIEW_ID=@p0 and 
       VR.WVIEW_TYPE=0 

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectViewInfoForViewResProjID TO MSProjectServerRole
GO



/* Query #16047 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectAndDSN
   @p0 INT
AS
--Select WPATH,MSP_WEB_PROJECTS.WDSN_ID,WDSN_LOGIN_ID,WDSN_PASSWORD From MSP_WEB_PROJECTS LEFT JOIN MSP_WEB_VIEW_DSNS ON MSP_WEB_PROJECTS.WDSN_ID=MSP_WEB_VIEW_DSNS.WDSN_ID Where WPROJ_ID=@p0 RETURN
Select WPATH,
       MSP_WEB_PROJECTS.WDSN_ID,
       WPROJ_TYPE,WDSN_LOGIN_ID,
       WDSN_PASSWORD 
  From MSP_WEB_PROJECTS 
       LEFT JOIN MSP_WEB_VIEW_DSNS ON MSP_WEB_PROJECTS.WDSN_ID=MSP_WEB_VIEW_DSNS.WDSN_ID 
 Where WPROJ_ID=@p0 

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectAndDSN TO MSProjectServerRole
GO



/* Query #16049 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetGanttSchemesForType
   @p0 INT
AS
--Select * From MSP_WEB_GANTT_SCHEMES Where WGANTT_SCHEME_TYPE=@p0 Order By WGANTT_SCHEME_ID RETURN
Select * 
  From MSP_WEB_GANTT_SCHEMES 
 Where WGANTT_SCHEME_TYPE = @p0 
 Order By WGANTT_SCHEME_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetGanttSchemesForType TO MSProjectServerRole
GO



/* Query #16050 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAllObsoleteNonNormalViews
   @p0 INT
AS
--Delete From MSP_WEB_VIEW_REPORTS Where WVIEW_REPORT_KIND<>0 and WVIEW_TYPE=@p0 RETURN(0)
Delete 
  From MSP_WEB_VIEW_REPORTS 
 Where WVIEW_REPORT_KIND <> 0 
   and WVIEW_TYPE = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAllObsoleteNonNormalViews TO MSProjectServerRole
GO



/* Query #16051 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllProjectFields
   @p0 INT,
   @p1 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, VF.WFIELD_NAME_OLEDB, VF.WFIELD_TEXTCONV_TYPE , MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and VF.WFIELD_IN_PROJECT_VIEW<>0 and VF.WTABLE_ID=@p1)
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.ATTRIB_FIELD_ID<>205521540 and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   Order By CV.CONV_STRING
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllProjectFields TO MSProjectServerRole
GO



/* Query #16052 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllPortfolioFields
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and VF.WFIELD_IN_PORTFOLIO_VIEW<>0)
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   Order By CV.CONV_STRING
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllPortfolioFields TO MSProjectServerRole
GO



/* Query #16053 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllWebclientFields
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and VF.WFIELD_IN_WEBCLIENT_VIEW<>0)
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   Order By CV.CONV_STRING
RETURN
END

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllWebclientFields TO MSProjectServerRole
GO



/* Query #16054 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CheckConvTableForValidEntries
   @p0 INT
AS
--Select count(*) from MSP_WEB_CONVERSIONS where LANG_ID=@p0 RETURN
Select count(*) 
  from MSP_WEB_CONVERSIONS 
 where LANG_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CheckConvTableForValidEntries TO MSProjectServerRole
GO



/* Query #16059 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllProjectFieldsWOEntOutlineCodeIDs
   @p0 INT,
   @p1 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, 
         CV.CONV_STRING, 
         VF.WFIELD_NAME_OLEDB, 
         VF.WFIELD_TEXTCONV_TYPE,
         MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV ON VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.ATTRIB_FIELD_ID<>205521540 and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   Where CV.LANG_ID = @p0 
     and VF.WFIELD_IN_PROJECT_VIEW <> 0 
     and VF.WTABLE_ID = @p1 
     and VF.WFIELD_ID not in (
		      -- Exclude the following fields from Filter Dropdown in Modify View page.
		      -- ResourceEnterpriseRMV20ID (20-20)
		      205521596,205521598,205521600,205521602,205521604,
		      205521606,205521608,205521610,205521612,205521614
         )
   Order By CV.CONV_STRING
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllProjectFieldsWOEntOutlineCodeIDs TO MSProjectServerRole
GO


/* Query #16080 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllTimeSheetFields
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and (VF.WFIELD_IN_WEBCLIENT_VIEW<>0 or VF.WFIELD_ID=2006))
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   where VF.WFIELD_ID NOT IN (1073741826,2179)
   Order By CV.CONV_STRING
RETURN
END

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllTimeSheetFields TO MSProjectServerRole
GO

/* Query #16081 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CopyViewReportsForViewID
   @p0 INT,
   @p1 nvarchar(255)
AS
BEGIN
	DECLARE @id int
	DECLARE @viewType int

	SELECT  @viewType = WVIEW_TYPE FROM MSP_WEB_VIEW_REPORTS WHERE WVIEW_ID = @p0
	INSERT INTO MSP_WEB_VIEW_REPORTS SELECT @p1,WVIEW_DESCRIPTION,WVIEW_TYPE,WVIEW_DISPLAY_TYPE,WVIEW_WORK_TYPE,WGANTT_SCHEME_ID,WTABLE_ID,WVIEW_FILTER_PARAM1,WVIEW_FILTER_PARAM2,WVIEW_FILTER_PARAM3,WVIEW_REPORT_KIND,WVIEW_PATH,WVIEW_OWC_PIVOT_XML,WVIEW_OWC_CHART_XML,WGROUP_SCHEME_ID,WVIEW_DEFAULT_SETTINGS,newid(),WVIEW_GROUPING_SORTING_PARAMS,WVIEW_FILTER_BY_RBS,WVIEW_OUTLINE_LEVEL,WVIEW_SPLITTER_POS FROM MSP_WEB_VIEW_REPORTS WHERE WVIEW_ID = @p0
	SELECT @id = WVIEW_ID FROM MSP_WEB_VIEW_REPORTS WHERE WVIEW_NAME = @p1 AND WVIEW_TYPE = @viewType
	INSERT INTO MSP_WEB_VIEW_REPORTS_FIELDS SELECT @id,WFIELD_ID,WVIEW_FIELD_ORDER,WVIEW_FIELD_WIDTH,WVIEW_FIELD_AUTOSIZE FROM MSP_WEB_VIEW_REPORTS_FIELDS WHERE WVIEW_ID = @p0
	INSERT INTO MSP_WEB_SECURITY_CATEGORY_OBJECTS SELECT WSEC_CAT_ID,WSEC_OBJ_TYPE,@id FROM MSP_WEB_SECURITY_CATEGORY_OBJECTS WHERE WSEC_OBJ_TYPE = 3 AND WSEC_OBJ_ID = @p0
RETURN
END

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CopyViewReportsForViewID TO MSProjectServerRole
GO


/* Query #17000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminNewAccountSetting
AS
--Select WADMIN_NEW_ACCOUNT_PRIVILEGE from MSP_WEB_ADMIN RETURN
Select WADMIN_NEW_ACCOUNT_PRIVILEGE 
  from MSP_WEB_ADMIN
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminNewAccountSetting TO MSProjectServerRole
GO



/* Query #17001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminLogonSetting
AS
Select WADMIN_AUTHENTICATION_TYPE, 
       WADMIN_MIN_PASSWORD_LENGTH
  from MSP_WEB_ADMIN
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminLogonSetting TO MSProjectServerRole
GO



/* Query #17002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminWeekStartOn
AS
--Select WADMIN_WEEK_STARTS_ON from MSP_WEB_ADMIN RETURN
Select WADMIN_WEEK_STARTS_ON 
  from MSP_WEB_ADMIN
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminWeekStartOn TO MSProjectServerRole
GO



/* Query #17003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminDelegationSetting
AS
--Select WADMIN_IS_DELEGATION_ALLOWED,WADMIN_WEEK_STARTS_ON,WADMIN_TRANS_HISTORY_DAYS from MSP_WEB_ADMIN RETURN
Select WADMIN_IS_DELEGATION_ALLOWED, 
       WADMIN_WEEK_STARTS_ON, 
       WADMIN_TRANS_HISTORY_DAYS 
  from MSP_WEB_ADMIN
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminDelegationSetting TO MSProjectServerRole
GO



/* Query #17004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEOrDResourceForResID
   @p0 INT
AS
--Select RES_NAME, WRES_GUID, WRES_USE_NT_LOGON, RESERVED_DATA1, RESERVED_DATA2, RESERVED_DATA3, RESERVED_DATA4, WRES_EMAIL, WRES_IS_MANAGER, WRES_IS_ADMIN, WRES_IS_ENABLED, RES_PHONETICS, WRES_LAST_CONNECT from MSP_WEB_RESOURCES where WRES_ID=@p0 RETURN
Select RES_NAME, 
       WRES_GUID, 
       RES_EUID,
       WRES_USE_NT_LOGON,
       WRES_NT_ACCOUNT,
       WRES_IS_PC2000, 
       RESERVED_DATA1, 
       RESERVED_DATA2, 
       RESERVED_DATA3, 
       RESERVED_DATA4, 
       WRES_EMAIL, 
       WRES_IS_MANAGER, 
       WRES_IS_ADMIN, 
       WRES_IS_ENABLED, 
       RES_PHONETICS, 
       WRES_CAN_LOGIN,
       WRES_COUNT_LICENSE,
       WRES_LAST_CONNECT,
       WRES_AD_GUID
  from MSP_WEB_RESOURCES 
 where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEOrDResourceForResID TO MSProjectServerRole
GO



/* Query #17005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEOrDResourceForResName
   @p0 NVARCHAR(255)
AS
--Select * from MSP_WEB_RESOURCES where lower(RES_NAME)=lower(@p0) RETURN
Select * 
  from MSP_WEB_RESOURCES 
 where lower(RES_NAME) = lower(@p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEOrDResourceForResName TO MSProjectServerRole
GO



/* Query #17006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteEOrDResourceForResID
   @p0 INT
AS
--Delete From MSP_WEB_RESOURCES Where WRES_ID=@p0 RETURN(0)
Delete 
  From MSP_WEB_RESOURCES 
 Where WRES_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteEOrDResourceForResID TO MSProjectServerRole
GO



/* Query #17007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllAssnForEOrDResID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET WRES_ID=@p1 where WRES_ID=@p0 RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WRES_ID = @p1 
 where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllAssnForEOrDResID TO MSProjectServerRole
GO



/* Query #17008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllAssnForEOrDMgrID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET WRES_ID_MGR=@p1 where WRES_ID_MGR=@p0 RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WRES_ID_MGR = @p1 
 where WRES_ID_MGR = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllAssnForEOrDMgrID TO MSProjectServerRole
GO



/* Query #17009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllMsgForEOrDSenderID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_MESSAGES SET WRES_ID_SENDER=@p1 where WRES_ID_SENDER=@p0 RETURN(0)
UPDATE MSP_WEB_MESSAGES 
   SET WRES_ID_SENDER = @p1 
 where WRES_ID_SENDER = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllMsgForEOrDSenderID TO MSProjectServerRole
GO



/* Query #17010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllMsgForEOrDRecipID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_MESSAGES SET WRES_ID_RECEIVER=@p1 where WRES_ID_RECEIVER=@p0 RETURN(0)
UPDATE MSP_WEB_MESSAGES 
   SET WRES_ID_RECEIVER = @p1 
 where WRES_ID_RECEIVER = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllMsgForEOrDRecipID TO MSProjectServerRole
GO



/* Query #17011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllWorkForEOrDResID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_WORK SET WRES_ID=@p1 where WRES_ID=@p0 RETURN(0)
UPDATE MSP_WEB_WORK 
   SET WRES_ID = @p1 
 where WRES_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllWorkForEOrDResID TO MSProjectServerRole
GO



/* Query #17012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllProjForEOrDResID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_PROJECTS SET WRES_ID=@p1 where WRES_ID=@p0 RETURN(0)
UPDATE MSP_WEB_PROJECTS 
   SET WRES_ID = @p1 
 where WRES_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllProjForEOrDResID TO MSProjectServerRole
GO



/* Query #17013 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllSReqForEOrDRecipID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_STATUS_REQUESTS SET WRES_ID_RECEIVER=@p1 where WRES_ID_RECEIVER=@p0 RETURN(0)
UPDATE MSP_WEB_STATUS_REQUESTS 
   SET WRES_ID_RECEIVER = @p1 
 where WRES_ID_RECEIVER = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllSReqForEOrDRecipID TO MSProjectServerRole
GO



/* Query #17014 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllSRptForEOrDMgrID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_STATUS_REPORTS SET WRES_ID_MGR=@p1 where WRES_ID_MGR=@p0 and WREPORT_IS_ENABLED<>0 RETURN(0)
UPDATE MSP_WEB_STATUS_REPORTS 
   SET WRES_ID_MGR = @p1 
 where WRES_ID_MGR = @p0 
   and WREPORT_IS_ENABLED <> 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllSRptForEOrDMgrID TO MSProjectServerRole
GO



/* Query #17015 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllSRspForEOrDResID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_STATUS_RESPONSES SET WRES_ID=@p1 where WRES_ID=@p0 RETURN(0)
UPDATE MSP_WEB_STATUS_RESPONSES 
   SET WRES_ID = @p1 
 where WRES_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllSRspForEOrDResID TO MSProjectServerRole
GO



/* Query #17016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAllSDistribForEOrDRecipID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_STATUS_DISTRIBUTION SET WRES_ID_DISTR_RECIP=@p1 where WRES_ID_DISTR_RECIP=@p0 RETURN(0)
UPDATE MSP_WEB_STATUS_DISTRIBUTION 
   SET WRES_ID_DISTR_RECIP = @p1 
 where WRES_ID_DISTR_RECIP = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAllSDistribForEOrDRecipID TO MSProjectServerRole
GO



/* Query #17017 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingAssignmentsForResID
   @p0 INT
AS
--Delete From MSP_WEB_ASSIGNMENTS Where WRES_ID=@p0 and WNWRK_ID>0 RETURN(0)
Delete 
  From MSP_WEB_ASSIGNMENTS 
 Where WRES_ID = @p0 
   and WNWRK_ID > 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingAssignmentsForResID TO MSProjectServerRole
GO



/* Query #17018 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DisableStatusReport
   @p0 INT
AS
--UPDATE MSP_WEB_STATUS_REPORTS SET WREPORT_IS_ENABLED=0 where WSR_ID=@p0 RETURN(0)
UPDATE MSP_WEB_STATUS_REPORTS 
   SET WREPORT_IS_ENABLED = 0 
 where WSR_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DisableStatusReport TO MSProjectServerRole
GO



/* Query #17019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DisableStatusReportRequests
   @p0 INT
AS
--UPDATE MSP_WEB_STATUS_REQUESTS SET WREQ_IS_ENABLED=0 where WSR_ID=@p0 RETURN(0)
UPDATE MSP_WEB_STATUS_REQUESTS 
   SET WREQ_IS_ENABLED = 0 
 where WSR_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DisableStatusReportRequests TO MSProjectServerRole
GO



/* Query #17020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingWorkForResID
   @p0 INT
AS
--delete from MSP_WEB_WORK where WRES_ID=@p0 and WASSN_ID in (select WASSN_ID from MSP_WEB_ASSIGNMENTS Where WRES_ID=@p0 and WNWRK_ID>0) RETURN(0)
delete 
  from MSP_WEB_WORK 
 where WRES_ID = @p0 
   and WASSN_ID in (select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     Where WRES_ID = @p0 
                       and WNWRK_ID > 0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingWorkForResID TO MSProjectServerRole
GO



/* Query #17021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CheckAssignmentConflictForMerge
   @p0 INT,
   @p1 INT
AS
--select WA.WASSN_ID from MSP_WEB_ASSIGNMENTS WA, MSP_WEB_ASSIGNMENTS WA1 where WA.WRES_ID=@p0 and WA1.WRES_ID=@p1 and WA.WPROJ_ID=WA1.WPROJ_ID and WA.TASK_UID=WA1.TASK_UID and WA.TASK_ID=WA1.TASK_ID and WA.WRES_ID_MGR<>0 and WA1.WRES_ID_MGR<>0 RETURN
select WA.WASSN_ID 
  from MSP_WEB_ASSIGNMENTS WA, 
       MSP_WEB_ASSIGNMENTS WA1 
 where WA.WRES_ID = @p0 
   and WA1.WRES_ID = @p1 
   and WA.WPROJ_ID = WA1.WPROJ_ID 
   and WA.TASK_UID = WA1.TASK_UID 
   and WA.TASK_ID = WA1.TASK_ID 
   and WA.WRES_ID_MGR <> 0 
   and WA1.WRES_ID_MGR <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CheckAssignmentConflictForMerge TO MSProjectServerRole
GO



/* Query #17022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CheckStatusResponseConflictForMerge
   @p0 INT,
   @p1 INT
AS
--select SR.WRESP_ID from MSP_WEB_STATUS_RESPONSES SR, MSP_WEB_STATUS_RESPONSES SR1 where SR.WRES_ID=@p0 AND SR1.WRES_ID=@p1 AND SR.WSR_ID=SR1.WSR_ID RETURN
select SR.WRESP_ID 
  from MSP_WEB_STATUS_RESPONSES SR, 
       MSP_WEB_STATUS_RESPONSES SR1 
 where SR.WRES_ID = @p0 
   AND SR1.WRES_ID = @p1 
   AND SR.WSR_ID = SR1.WSR_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CheckStatusResponseConflictForMerge TO MSProjectServerRole
GO



/* Query #17023 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CheckLeadRoleConflictForMerge
   @p0 INT,
   @p1 INT
AS
--select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WRES_ID=@p0 and WRES_ID_TEAM_LEAD=@p1) or (WRES_ID=@p1 and WRES_ID_TEAM_LEAD=@p0) RETURN
select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WRES_ID = @p0 
           and WRES_ID_TEAM_LEAD = @p1) 
    or (WRES_ID = @p1 
           and WRES_ID_TEAM_LEAD = @p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CheckLeadRoleConflictForMerge TO MSProjectServerRole
GO



/* Query #17024 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CheckStatusRequestConflictForMerge
   @p0 INT,
   @p1 INT
AS
--select SR.WSR_ID from MSP_WEB_STATUS_REQUESTS SR, MSP_WEB_STATUS_REQUESTS SR1 where SR.WRES_ID_RECEIVER=@p0 AND SR1.WRES_ID_RECEIVER=@p1 AND SR.WSR_ID=SR1.WSR_ID RETURN
select SR.WSR_ID 
  from MSP_WEB_STATUS_REQUESTS SR, 
       MSP_WEB_STATUS_REQUESTS SR1 
 where SR.WRES_ID_RECEIVER = @p0 
   AND SR1.WRES_ID_RECEIVER = @p1 
   AND SR.WSR_ID = SR1.WSR_ID
   AND SR.WREQ_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CheckStatusRequestConflictForMerge TO MSProjectServerRole
GO


/* Query #17025 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEOrDResourceForNTAccount
   @p0 NVARCHAR(255)
AS
Select * 
  From MSP_WEB_RESOURCES 
 Where WRES_USE_NT_LOGON<>0 
   and lower(WRES_NT_ACCOUNT)=lower(@p0) 

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEOrDResourceForNTAccount TO MSProjectServerRole
GO


/* Query #17027 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllActiveResIDCookies
AS
--Select WRES_ID, RESERVED_DATA3, RESERVED_DATA4 from MSP_WEB_RESOURCES where WRES_IS_ENABLED<>0 RETURN
Select WRES_ID, 
       RESERVED_DATA3, 
       RESERVED_DATA4 
  from MSP_WEB_RESOURCES 
 where WRES_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllActiveResIDCookies TO MSProjectServerRole
GO



/* Query #17028 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateResourceCookiesForEOrDResID
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Update MSP_WEB_RESOURCES Set RESERVED_DATA3=@p1, RESERVED_DATA4=@p2 where WRES_ID=@p0 RETURN(0)
Update MSP_WEB_RESOURCES 
   Set RESERVED_DATA3 = @p1, 
       RESERVED_DATA4 = @p2 
 where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateResourceCookiesForEOrDResID TO MSProjectServerRole
GO



/* Query #17029 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateResourcePwdForEOrDResID
   @pResID  INT,
   @pPasswd sysname,
   @pPasswdHashed nvarchar(255)
AS
BEGIN
  -- Don't put this SP call into any user-defined transaction.
  -- Because sp_password cannot be put into a user-defined transaction.
  declare @fNT        tinyint
  declare @sResName   nvarchar(255)
  declare @iEUID      INT

  select @fNT = WRES_USE_NT_LOGON, 
         @sResName = RES_NAME,
         @iEUID = RES_EUID
    from MSP_WEB_RESOURCES
   where WRES_ID = @pResID

  if (@@ROWCOUNT <> 1) RETURN

  -- Not need to set password for NT Account
  if (@fNT > 0) RETURN

  -- Set the password for the resource
  Update MSP_WEB_RESOURCES Set WRES_IS_PC2000 = 0, WRES_PASSWORD = @pPasswdHashed where WRES_ID = @pResID

END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateResourcePwdForEOrDResID TO MSProjectServerRole
GO



/* Query #17030 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DisableAllPJAccounts
AS
--Update MSP_WEB_RESOURCES Set WRES_IS_ENABLED=0 where WRES_USE_NT_LOGON=0 RETURN(0)
Update MSP_WEB_RESOURCES 
   Set WRES_IS_ENABLED = 0 
 where WRES_USE_NT_LOGON = 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DisableAllPJAccounts TO MSProjectServerRole
GO



/* Query #17031 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DisableAllNTAccounts
AS
--Update MSP_WEB_RESOURCES Set WRES_IS_ENABLED=0 where WRES_USE_NT_LOGON<>0 RETURN(0)
Update MSP_WEB_RESOURCES 
   Set WRES_IS_ENABLED = 0 
 where WRES_USE_NT_LOGON <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DisableAllNTAccounts TO MSProjectServerRole
GO



/* Query #17032 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllActivePJAccounts
AS
Select WRES_ID 
  from MSP_WEB_RESOURCES 
 where WRES_IS_ENABLED <> 0 
   and WRES_USE_NT_LOGON = 0
   and WRES_CAN_LOGIN = 1
   and WRES_COUNT_LICENSE = 1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllActivePJAccounts TO MSProjectServerRole
GO



/* Query #17033 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllActiveNTAccounts
AS
--Select WRES_ID from MSP_WEB_RESOURCES where WRES_IS_ENABLED<>0 and WRES_USE_NT_LOGON<>0 RETURN
Select WRES_ID 
  from MSP_WEB_RESOURCES 
 where WRES_IS_ENABLED <> 0 
   and WRES_USE_NT_LOGON <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllActiveNTAccounts TO MSProjectServerRole
GO



/* Query #17034 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResIDNameForEOrDRes
AS
--Select WRES_ID, RES_NAME from MSP_WEB_RESOURCES RETURN
Select WRES_ID, 
       RES_NAME 
  from MSP_WEB_RESOURCES
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResIDNameForEOrDRes TO MSProjectServerRole
GO



/* Query #17100 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAdminNewAccountSetting
   @p0 INT
AS
--Update MSP_WEB_ADMIN Set WADMIN_NEW_ACCOUNT_PRIVILEGE=@p0 RETURN(0)
Update MSP_WEB_ADMIN 
   Set WADMIN_NEW_ACCOUNT_PRIVILEGE = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAdminNewAccountSetting TO MSProjectServerRole
GO



/* Query #17101 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAdminLogonSetting
   @p0 INT,
   @p1 INT
AS
Update MSP_WEB_ADMIN 
   Set WADMIN_AUTHENTICATION_TYPE = @p0, 
       WADMIN_MIN_PASSWORD_LENGTH = @p1
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAdminLogonSetting TO MSProjectServerRole
GO



/* Query #17102 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAdminWeekStartOn
   @p0 INT
AS
--Update MSP_WEB_ADMIN Set WADMIN_WEEK_STARTS_ON=@p0 RETURN(0)
Update MSP_WEB_ADMIN 
   Set WADMIN_WEEK_STARTS_ON = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAdminWeekStartOn TO MSProjectServerRole
GO



/* Query #17103 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAdminDelegationSetting
   @p0 BIT
AS
--Update MSP_WEB_ADMIN Set WADMIN_IS_DELEGATION_ALLOWED=@p0 RETURN(0)
Update MSP_WEB_ADMIN 
   Set WADMIN_IS_DELEGATION_ALLOWED = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAdminDelegationSetting TO MSProjectServerRole
GO



/* Query #17201 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnForResId
   @p0 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnForResId TO MSProjectServerRole
GO



/* Query #17202 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_FINISH_DATE < @p0 
   and WRES_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17203 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_START_DATE>@p0 and ASSN_FINISH_DATE<@p1 and WRES_ID=@p2 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_START_DATE > @p0 
   and ASSN_FINISH_DATE < @p1 
   and WRES_ID = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17204 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssn
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssn TO MSProjectServerRole
GO



/* Query #17205 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnOlderThan
   @p0 DATETIME
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_FINISH_DATE < @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnOlderThan TO MSProjectServerRole
GO



/* Query #17206 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_START_DATE>@p0 and ASSN_FINISH_DATE<@p1 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_START_DATE > @p0 
   and ASSN_FINISH_DATE < @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnSentBtw TO MSProjectServerRole
GO



/* Query #17207 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCompletedAssnForResId
   @p0 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_REM_WORK = 0 
   and WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCompletedAssnForResId TO MSProjectServerRole
GO



/* Query #17208 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_REM_WORK = 0 
   and ASSN_FINISH_DATE < @p0 
   and WRES_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCompletedAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17209 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_START_DATE>@p0 and ASSN_FINISH_DATE<@p1 and WRES_ID=@p2 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_REM_WORK = 0 
   and ASSN_START_DATE > @p0 
   and ASSN_FINISH_DATE < @p1 
   and WRES_ID = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCompletedAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17210 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCompletedAssn
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_REM_WORK = 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCompletedAssn TO MSProjectServerRole
GO



/* Query #17211 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCompletedAssnOlderThan
   @p0 DATETIME
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_REM_WORK = 0 
   and ASSN_FINISH_DATE < @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCompletedAssnOlderThan TO MSProjectServerRole
GO



/* Query #17212 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
--Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_START_DATE>@p0 and ASSN_FINISH_DATE<@p1 RETURN
Select WASSN_ID 
  from MSP_WEB_ASSIGNMENTS 
 where (WNWRK_ID = -1 
            or WNWRK_ID is NULL) 
   and ASSN_REM_WORK = 0 
   and ASSN_START_DATE > @p0 
   and ASSN_FINISH_DATE < @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17221 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMsgForResId
   @p0 INT
AS
--Select WMSG_ID from MSP_WEB_MESSAGES where WRES_ID_RECEIVER=@p0 RETURN
Select WMSG_ID 
  from MSP_WEB_MESSAGES 
 where WRES_ID_RECEIVER = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMsgForResId TO MSProjectServerRole
GO



/* Query #17222 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMsgOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0 and WRES_ID_RECEIVER=@p1 RETURN
Select WMSG_ID 
  from MSP_WEB_MESSAGES 
 where WMSG_TIME < @p0 
   and WRES_ID_RECEIVER = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMsgOlderThanForResId TO MSProjectServerRole
GO



/* Query #17223 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMsgSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
--Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME>@p0 and WMSG_TIME<@p1 and WRES_ID_RECEIVER=@p2 RETURN
Select WMSG_ID 
  from MSP_WEB_MESSAGES 
 where WMSG_TIME > @p0 
   and WMSG_TIME < @p1 
   and WRES_ID_RECEIVER = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMsgSentBtwForResId TO MSProjectServerRole
GO



/* Query #17224 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMsg
AS
Select WMSG_ID from MSP_WEB_MESSAGES RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMsg TO MSProjectServerRole
GO



/* Query #17225 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMsgOlderThan
   @p0 DATETIME
AS
--Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0 RETURN
Select WMSG_ID 
  from MSP_WEB_MESSAGES 
 where WMSG_TIME < @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMsgOlderThan TO MSProjectServerRole
GO



/* Query #17226 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMsgSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
--Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME>@p0 and WMSG_TIME<@p1 RETURN
Select WMSG_ID 
  from MSP_WEB_MESSAGES 
 where WMSG_TIME > @p0 
   and WMSG_TIME < @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMsgSentBtw TO MSProjectServerRole
GO



/* Query #17241 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSRespForResId
   @p0 INT
AS
--Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WRES_ID=@p0 RETURN
Select WRESP_ID 
  from MSP_WEB_STATUS_RESPONSES 
 where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSRespForResId TO MSProjectServerRole
GO



/* Query #17242 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSRespOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_FINISH<@p0 and WRES_ID=@p1 RETURN
Select WRESP_ID 
  from MSP_WEB_STATUS_RESPONSES 
 where WSRESP_PERIOD_FINISH < @p0 
   and WRES_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSRespOlderThanForResId TO MSProjectServerRole
GO



/* Query #17243 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSRespSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
--Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_START>@p0 and WSRESP_PERIOD_FINISH<@p1 and WRES_ID=@p2 RETURN
Select WRESP_ID 
  from MSP_WEB_STATUS_RESPONSES 
 where WSRESP_PERIOD_START > @p0 
   and WSRESP_PERIOD_FINISH < @p1 
   and WRES_ID = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSRespSentBtwForResId TO MSProjectServerRole
GO



/* Query #17244 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSResp
AS
Select WRESP_ID from MSP_WEB_STATUS_RESPONSES RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSResp TO MSProjectServerRole
GO



/* Query #17245 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSRespOlderThan
   @p0 DATETIME
AS
--Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_FINISH<@p0 RETURN
Select WRESP_ID 
  from MSP_WEB_STATUS_RESPONSES 
 where WSRESP_PERIOD_FINISH < @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSRespOlderThan TO MSProjectServerRole
GO



/* Query #17246 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSRespSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
--Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_START>@p0 and WSRESP_PERIOD_FINISH<@p1 RETURN
Select WRESP_ID 
  from MSP_WEB_STATUS_RESPONSES 
 where WSRESP_PERIOD_START > @p0 
   and WSRESP_PERIOD_FINISH < @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSRespSentBtw TO MSProjectServerRole
GO



/* Query #17306 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminLockDownInfo
AS
Select RESERVED_DATA3, RESERVED_DATA4 from MSP_WEB_RESERVED_DATA RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminLockDownInfo TO MSProjectServerRole
GO

/* Query #17307 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminAccountSettings
AS
Select *
  from MSP_WEB_ADMIN
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminAccountSettings TO MSProjectServerRole
GO

/* Query #17308 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetOrgAcctCreationFromProjSettings
AS
BEGIN
  declare @fAllow    tinyint
  declare @dwNewAcct INT

  set @dwNewAcct = 0

  set @fAllow = dbo.MSP_WEB_FN_SEC_CheckOrgPermission(901)
  if (@fAllow = 1)
    set @dwNewAcct = @dwNewAcct + 1

  set @fAllow = dbo.MSP_WEB_FN_SEC_CheckOrgPermission(902)
  if (@fAllow = 1)
    set @dwNewAcct = @dwNewAcct + 2

  -- return as recordset
  select @dwNewAcct as WADMIN_NEW_ACCOUNT_PRIVILEGE
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetOrgAcctCreationFromProjSettings TO MSProjectServerRole
GO


/* Query #17404 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAdminLogonSettingNoPwdChg
   @p0 INT
AS
Update MSP_WEB_ADMIN 
   Set WADMIN_AUTHENTICATION_TYPE = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAdminLogonSettingNoPwdChg TO MSProjectServerRole
GO



/* Query #17406 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAdminLockDownInfo
   @p0 INT,
   @p1 INT
AS
--Update MSP_WEB_RESERVED_DATA Set RESERVED_DATA3=@p0, RESERVED_DATA4=@p1 RETURN(0)
Update MSP_WEB_RESERVED_DATA 
   Set RESERVED_DATA3 = @p0, 
       RESERVED_DATA4 = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAdminLockDownInfo TO MSProjectServerRole
GO



/* Query #17500 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForAssn
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL)) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForAssn TO MSProjectServerRole
GO



/* Query #17501 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForAssn
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL)) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForAssn TO MSProjectServerRole
GO



/* Query #17502 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssn
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL)) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssn TO MSProjectServerRole
GO



/* Query #17503 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForAssn
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL))) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL))) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL))) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL)))
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForAssn TO MSProjectServerRole
GO



/* Query #17504 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssn
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL)) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssn TO MSProjectServerRole
GO



/* Query #17505 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForAssn
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL)) RETURN(0)

Delete
  From MSP_WEB_WORK_ADJUSTED
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where TASK_ID<>0 and (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))

Delete
  From MSP_WEB_WORK_APPROVAL
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where TASK_ID<>0 and (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where TASK_ID<>0 and (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForAssn TO MSProjectServerRole
GO



/* Query #17506 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssn
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssn TO MSProjectServerRole
GO



/* Query #17507 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssn
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssn TO MSProjectServerRole
GO



/* Query #17508 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssn
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssn TO MSProjectServerRole
GO



/* Query #17509 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssn
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0)) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0)) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_REM_WORK = 0)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_REM_WORK = 0))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssn TO MSProjectServerRole
GO



/* Query #17510 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssn
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssn TO MSProjectServerRole
GO



/* Query #17511 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssn
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0) RETURN(0)
Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssn TO MSProjectServerRole
GO



/* Query #17512 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnForResId TO MSProjectServerRole
GO



/* Query #17513 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForAssnForResId TO MSProjectServerRole
GO



/* Query #17514 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnForResId TO MSProjectServerRole
GO



/* Query #17515 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForAssnForResId
   @p0 INT
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0)) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0)) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and WRES_ID = @p0)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and WRES_ID = @p0))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForAssnForResId TO MSProjectServerRole
GO



/* Query #17516 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnForResId
   @p0 INT
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnForResId TO MSProjectServerRole
GO



/* Query #17517 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and WRES_ID=@p0) RETURN(0)

Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnForResId TO MSProjectServerRole
GO



/* Query #17518 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnForResId TO MSProjectServerRole
GO



/* Query #17519 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnForResId TO MSProjectServerRole
GO



/* Query #17520 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnForResId TO MSProjectServerRole
GO



/* Query #17521 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnForResId
   @p0 INT
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0)) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0)) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_REM_WORK = 0 
                                            and WRES_ID = @p0)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_REM_WORK = 0 
                                                    and WRES_ID = @p0))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnForResId TO MSProjectServerRole
GO



/* Query #17522 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnForResId
   @p0 INT
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnForResId TO MSProjectServerRole
GO



/* Query #17523 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnForResId
   @p0 INT
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and WRES_ID=@p0) RETURN(0)

Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnForResId TO MSProjectServerRole
GO



/* Query #17524 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnOlderThan TO MSProjectServerRole
GO



/* Query #17525 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForAssnOlderThan TO MSProjectServerRole
GO



/* Query #17526 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnOlderThan TO MSProjectServerRole
GO



/* Query #17527 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForAssnOlderThan
   @p0 DATETIME
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0)) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0)) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_FINISH_DATE < @p0)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_FINISH_DATE < @p0))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForAssnOlderThan TO MSProjectServerRole
GO



/* Query #17528 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnOlderThan
   @p0 DATETIME
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnOlderThan TO MSProjectServerRole
GO



/* Query #17529 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0) RETURN(0)

Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)


Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)



Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnOlderThan TO MSProjectServerRole
GO



/* Query #17530 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnOlderThan TO MSProjectServerRole
GO



/* Query #17531 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnOlderThan TO MSProjectServerRole
GO



/* Query #17532 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnOlderThan TO MSProjectServerRole
GO



/* Query #17533 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnOlderThan
   @p0 DATETIME
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0)) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0)) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_REM_WORK = 0 
                                            and ASSN_FINISH_DATE < @p0)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_REM_WORK = 0 
                                                    and ASSN_FINISH_DATE < @p0))

RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnOlderThan TO MSProjectServerRole
GO



/* Query #17534 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnOlderThan
   @p0 DATETIME
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnOlderThan TO MSProjectServerRole
GO



/* Query #17535 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0) RETURN(0)
Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnOlderThan TO MSProjectServerRole
GO



/* Query #17536 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17537 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17538 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17539 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1)) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1)) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_FINISH_DATE < @p0 
                                            and WRES_ID = @p1)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_FINISH_DATE < @p0 
                                                    and WRES_ID = @p1))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17540 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17541 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)

Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17542 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_WORK where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17543 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17544 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17545 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--delete from MSP_WEB_DELEGATIONS where WDELEG_ID in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1)) and WDELEG_ID not in (select WDELEG_ID from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID not in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1)) RETURN(0)
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_REM_WORK = 0 
                                            and ASSN_FINISH_DATE < @p0 
                                            and WRES_ID = @p1)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_REM_WORK = 0 
                                                    and ASSN_FINISH_DATE < @p0 
                                                    and WRES_ID = @p1))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17546 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete from MSP_WEB_DELEGATION_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17547 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_ASSIGNMENTS where WASSN_ID in (Select WASSN_ID from MSP_WEB_ASSIGNMENTS where (WNWRK_ID=-1 or WNWRK_ID is NULL) and ASSN_REM_WORK=0 and ASSN_FINISH_DATE<@p0 and WRES_ID=@p1) RETURN(0)

Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnOlderThanForResId TO MSProjectServerRole
GO



/* Query #17548 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnSentBtw TO MSProjectServerRole
GO



/* Query #17549 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForAssnSentBtw TO MSProjectServerRole
GO



/* Query #17550 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnSentBtw TO MSProjectServerRole
GO



/* Query #17551 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_START_DATE >= @p0 
                                            and ASSN_FINISH_DATE < @p1+1)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_START_DATE >= @p0 
                                                    and ASSN_FINISH_DATE < @p1+1))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForAssnSentBtw TO MSProjectServerRole
GO



/* Query #17552 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnSentBtw TO MSProjectServerRole
GO



/* Query #17553 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS

Delete 
  From MSP_WEB_WORK_ADJUSTED 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)


Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)


Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnSentBtw TO MSProjectServerRole
GO



/* Query #17554 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17555 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17556 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17557 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_REM_WORK = 0 
                                            and ASSN_START_DATE >= @p0 
                                            and ASSN_FINISH_DATE < @p1+1)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_REM_WORK = 0 
                                                    and ASSN_START_DATE >= @p0 
                                                    and ASSN_FINISH_DATE < @p1+1))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17558 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17559 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS

Delete 
  From MSP_WEB_WORK_ADJUSTED
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17560 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17561 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17562 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17563 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_START_DATE >= @p0 
                                            and ASSN_FINISH_DATE < @p1+1
                                            and WRES_ID = @p2)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_START_DATE >= @p0 
                                                    and ASSN_FINISH_DATE < @p1+1
                                                    and WRES_ID = @p2))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17564 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17565 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS

Delete 
  From MSP_WEB_WORK_ADJUSTED
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)

Delete 
  From MSP_WEB_WORK_APPROVAL 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17566 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_WORK 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteActualsForCompletedAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17567 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteCFForCompletedAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17568 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForCompletedAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17569 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
delete 
  from MSP_WEB_DELEGATIONS 
 where WDELEG_ID in (select WDELEG_ID 
                       from MSP_WEB_DELEGATION_ASSIGNMENTS 
                      where WASSN_ID in (Select WASSN_ID 
                                           from MSP_WEB_ASSIGNMENTS 
                                          where (WNWRK_ID = -1 
                                             or WNWRK_ID is NULL) 
                                            and ASSN_REM_WORK = 0 
                                            and ASSN_START_DATE >= @p0 
                                            and ASSN_FINISH_DATE < @p1+1
                                            and WRES_ID = @p2)) 
   and WDELEG_ID not in (select WDELEG_ID 
                           from MSP_WEB_DELEGATION_ASSIGNMENTS 
                          where WASSN_ID not in (Select WASSN_ID 
                                                   from MSP_WEB_ASSIGNMENTS 
                                                  where (WNWRK_ID = -1 
                                                     or WNWRK_ID is NULL) 
                                                    and ASSN_REM_WORK = 0 
                                                    and ASSN_START_DATE >= @p0 
                                                    and ASSN_FINISH_DATE < @p1+1
                                                    and WRES_ID = @p2))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationsForCompletedAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17570 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  from MSP_WEB_DELEGATION_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DelegationAssnsForCompletedAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17571 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS

Delete 
  From MSP_WEB_WORK_ADJUSTED
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)

Delete 
  From MSP_WEB_WORK_APPROVAL
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)

Delete 
  From MSP_WEB_ASSIGNMENTS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteAssnForCompletedAssnSentBtwForResId TO MSProjectServerRole
GO



/* Query #17572 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsg
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsg TO MSProjectServerRole
GO



/* Query #17574 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsg
AS
--Delete From MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_NONWORKING 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsg TO MSProjectServerRole
GO



/* Query #17575 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsg
AS
--Delete From MSP_WEB_NONWORKING where WNONWORK_ID in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES)) and WNONWORK_ID not in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID not in (Select WMSG_ID from MSP_WEB_MESSAGES)) RETURN(0)
Delete 
  From MSP_WEB_NONWORKING 
 where WNONWORK_ID in (select WNONWORK_ID 
                         from MSP_WEB_MESSAGES_NONWORKING 
                        where WMSG_ID in (Select WMSG_ID 
                                            from MSP_WEB_MESSAGES)) 
   and WNONWORK_ID not in (select WNONWORK_ID 
                             from MSP_WEB_MESSAGES_NONWORKING 
                            where WMSG_ID not in (Select WMSG_ID 
                                                    from MSP_WEB_MESSAGES))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsg TO MSProjectServerRole
GO



/* Query #17576 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgForMsg
AS
--Delete From MSP_WEB_MESSAGES where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgForMsg TO MSProjectServerRole
GO



/* Query #17577 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgForResId
   @p0 INT
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WRES_ID_RECEIVER=@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WRES_ID_RECEIVER = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgForResId TO MSProjectServerRole
GO



/* Query #17579 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgForResId
   @p0 INT
AS
--Delete From MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WRES_ID_RECEIVER=@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_NONWORKING 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WRES_ID_RECEIVER = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgForResId TO MSProjectServerRole
GO



/* Query #17580 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgForResId
   @p0 INT
AS
--Delete From MSP_WEB_NONWORKING where WNONWORK_ID in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WRES_ID_RECEIVER=@p0)) and WNONWORK_ID not in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID not in (Select WMSG_ID from MSP_WEB_MESSAGES where WRES_ID_RECEIVER=@p0)) RETURN(0)
Delete 
  From MSP_WEB_NONWORKING 
 where WNONWORK_ID in (select WNONWORK_ID 
                         from MSP_WEB_MESSAGES_NONWORKING 
                        where WMSG_ID in (Select WMSG_ID 
                                            from MSP_WEB_MESSAGES 
                                           where WRES_ID_RECEIVER = @p0)) 
   and WNONWORK_ID not in (select WNONWORK_ID 
                             from MSP_WEB_MESSAGES_NONWORKING 
                            where WMSG_ID not in (Select WMSG_ID 
                                                    from MSP_WEB_MESSAGES 
                                                   where WRES_ID_RECEIVER = @p0))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgForResId TO MSProjectServerRole
GO



/* Query #17581 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgForResId
   @p0 INT
AS
--Delete From MSP_WEB_MESSAGES where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WRES_ID_RECEIVER=@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WRES_ID_RECEIVER = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgForResId TO MSProjectServerRole
GO



/* Query #17582 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgOlderThan TO MSProjectServerRole
GO



/* Query #17584 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_NONWORKING 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgOlderThan TO MSProjectServerRole
GO



/* Query #17585 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_NONWORKING where WNONWORK_ID in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0)) and WNONWORK_ID not in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID not in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0)) RETURN(0)
Delete 
  From MSP_WEB_NONWORKING 
 where WNONWORK_ID in (select WNONWORK_ID 
                         from MSP_WEB_MESSAGES_NONWORKING 
                        where WMSG_ID in (Select WMSG_ID 
                                            from MSP_WEB_MESSAGES 
                                           where WMSG_TIME < @p0)) 
   and WNONWORK_ID not in (select WNONWORK_ID 
                             from MSP_WEB_MESSAGES_NONWORKING 
                            where WMSG_ID not in (Select WMSG_ID 
                                                    from MSP_WEB_MESSAGES 
                                                   where WMSG_TIME < @p0))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgOlderThan TO MSProjectServerRole
GO



/* Query #17586 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_MESSAGES where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgOlderThan TO MSProjectServerRole
GO



/* Query #17587 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_MESSAGES_ASSIGNMENTS where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0 and WRES_ID_RECEIVER=@p1) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME < @p0 
                      and WRES_ID_RECEIVER = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgOlderThanForResId TO MSProjectServerRole
GO



/* Query #17589 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0 and WRES_ID_RECEIVER=@p1) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES_NONWORKING 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME < @p0 
                      and WRES_ID_RECEIVER = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgOlderThanForResId TO MSProjectServerRole
GO



/* Query #17590 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_NONWORKING where WNONWORK_ID in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0 and WRES_ID_RECEIVER=@p1)) and WNONWORK_ID not in (select WNONWORK_ID from MSP_WEB_MESSAGES_NONWORKING where WMSG_ID not in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0 and WRES_ID_RECEIVER=@p1)) RETURN(0)
Delete 
  From MSP_WEB_NONWORKING 
 where WNONWORK_ID in (select WNONWORK_ID 
                         from MSP_WEB_MESSAGES_NONWORKING 
                        where WMSG_ID in (Select WMSG_ID 
                                            from MSP_WEB_MESSAGES 
                                           where WMSG_TIME < @p0 
                                             and WRES_ID_RECEIVER = @p1)) 
   and WNONWORK_ID not in (select WNONWORK_ID 
                             from MSP_WEB_MESSAGES_NONWORKING 
                            where WMSG_ID not in (Select WMSG_ID 
                                                    from MSP_WEB_MESSAGES 
                                                   where WMSG_TIME < @p0 
                                                     and WRES_ID_RECEIVER = @p1))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgOlderThanForResId TO MSProjectServerRole
GO



/* Query #17591 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_MESSAGES where WMSG_ID in (Select WMSG_ID from MSP_WEB_MESSAGES where WMSG_TIME<@p0 and WRES_ID_RECEIVER=@p1) RETURN(0)
Delete 
  From MSP_WEB_MESSAGES 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME < @p0 
                      and WRES_ID_RECEIVER = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgOlderThanForResId TO MSProjectServerRole
GO



/* Query #17592 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME >= @p0 
                      and WMSG_TIME < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgSentBtw TO MSProjectServerRole
GO



/* Query #17594 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_MESSAGES_NONWORKING 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME >= @p0 
                      and WMSG_TIME < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgSentBtw TO MSProjectServerRole
GO



/* Query #17595 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_NONWORKING 
 where WNONWORK_ID in (select WNONWORK_ID 
                         from MSP_WEB_MESSAGES_NONWORKING 
                        where WMSG_ID in (Select WMSG_ID 
                                            from MSP_WEB_MESSAGES 
                                           where WMSG_TIME >= @p0 
                                             and WMSG_TIME < @p1+1)) 
   and WNONWORK_ID not in (select WNONWORK_ID 
                             from MSP_WEB_MESSAGES_NONWORKING 
                            where WMSG_ID not in (Select WMSG_ID 
                                                    from MSP_WEB_MESSAGES 
                                                   where WMSG_TIME >= @p0 
                                                     and WMSG_TIME < @p1+1))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgSentBtw TO MSProjectServerRole
GO



/* Query #17596 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_MESSAGES 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME >= @p0 
                      and WMSG_TIME < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgSentBtw TO MSProjectServerRole
GO



/* Query #17597 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_MESSAGES_ASSIGNMENTS 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME >= @p0 
                      and WMSG_TIME < @p1+1 
                      and WRES_ID_RECEIVER = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgAssnLinkForMsgSentBtwForResId TO MSProjectServerRole
GO



/* Query #17599 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_MESSAGES_NONWORKING 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME >= @p0 
                      and WMSG_TIME < @p1+1
                      and WRES_ID_RECEIVER = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgNonworkingForMsgSentBtwForResId TO MSProjectServerRole
GO



/* Query #17600 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_NONWORKING 
 where WNONWORK_ID in (select WNONWORK_ID 
                         from MSP_WEB_MESSAGES_NONWORKING 
                        where WMSG_ID in (Select WMSG_ID 
                                            from MSP_WEB_MESSAGES 
                                           where WMSG_TIME >= @p0 
                                             and WMSG_TIME < @p1+1
                                             and WRES_ID_RECEIVER = @p2)) 
   and WNONWORK_ID not in (select WNONWORK_ID 
                             from MSP_WEB_MESSAGES_NONWORKING 
                            where WMSG_ID not in (Select WMSG_ID 
                                                    from MSP_WEB_MESSAGES 
                                                   where WMSG_TIME > @p0 
                                                     and WMSG_TIME < @p1+1
                                                     and WRES_ID_RECEIVER = @p2))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNonworkingForMsgSentBtwForResId TO MSProjectServerRole
GO



/* Query #17601 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_MESSAGES 
 where WMSG_ID in (Select WMSG_ID 
                     from MSP_WEB_MESSAGES 
                    where WMSG_TIME >= @p0 
                      and WMSG_TIME < @p1+1
                      and WRES_ID_RECEIVER = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteMsgForMsgSentBtwForResId TO MSProjectServerRole
GO



/* Query #17602 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSDistForSResp
AS
--Delete From MSP_WEB_STATUS_DISTRIBUTION where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES) RETURN(0)
Delete 
  From MSP_WEB_STATUS_DISTRIBUTION 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSDistForSResp TO MSProjectServerRole
GO



/* Query #17603 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSRespForSResp
AS
--Delete From MSP_WEB_STATUS_RESPONSES where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES) RETURN(0)
Delete 
  From MSP_WEB_STATUS_RESPONSES 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSRespForSResp TO MSProjectServerRole
GO



/* Query #17604 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespForResId
   @p0 INT
AS
--Delete From MSP_WEB_STATUS_DISTRIBUTION where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_STATUS_DISTRIBUTION 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespForResId TO MSProjectServerRole
GO



/* Query #17605 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespForResId
   @p0 INT
AS
--Delete From MSP_WEB_STATUS_RESPONSES where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WRES_ID=@p0) RETURN(0)
Delete 
  From MSP_WEB_STATUS_RESPONSES 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespForResId TO MSProjectServerRole
GO



/* Query #17606 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_STATUS_DISTRIBUTION where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_FINISH<@p0) RETURN(0)
Delete 
  From MSP_WEB_STATUS_DISTRIBUTION 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_FINISH < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespOlderThan TO MSProjectServerRole
GO



/* Query #17607 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespOlderThan
   @p0 DATETIME
AS
--Delete From MSP_WEB_STATUS_RESPONSES where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_FINISH<@p0) RETURN(0)
Delete 
  From MSP_WEB_STATUS_RESPONSES 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_FINISH < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespOlderThan TO MSProjectServerRole
GO



/* Query #17608 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_STATUS_DISTRIBUTION where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_FINISH<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_STATUS_DISTRIBUTION 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_FINISH < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespOlderThanForResId TO MSProjectServerRole
GO



/* Query #17609 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
--Delete From MSP_WEB_STATUS_RESPONSES where WRESP_ID in (Select WRESP_ID from MSP_WEB_STATUS_RESPONSES where WSRESP_PERIOD_FINISH<@p0 and WRES_ID=@p1) RETURN(0)
Delete 
  From MSP_WEB_STATUS_RESPONSES 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_FINISH < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespOlderThanForResId TO MSProjectServerRole
GO



/* Query #17610 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_STATUS_DISTRIBUTION 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_START >= @p0 
                       and WSRESP_PERIOD_FINISH < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespSentBtw TO MSProjectServerRole
GO



/* Query #17611 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_STATUS_RESPONSES 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_START >= @p0 
                       and WSRESP_PERIOD_FINISH < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespSentBtw TO MSProjectServerRole
GO



/* Query #17612 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_STATUS_DISTRIBUTION 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_START >= @p0 
                       and WSRESP_PERIOD_FINISH < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSDistForSRespSentBtwForResId TO MSProjectServerRole
GO



/* Query #17613 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_STATUS_RESPONSES 
 where WRESP_ID in (Select WRESP_ID 
                      from MSP_WEB_STATUS_RESPONSES 
                     where WSRESP_PERIOD_START >= @p0 
                       and WSRESP_PERIOD_FINISH < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteSRespForSRespSentBtwForResId TO MSProjectServerRole
GO



/* Query #17701 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MergeUserDelegatee
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_DELEGATIONS set WRES_ID_DELEGATEE=@p1 where WRES_ID_DELEGATEE=@p0 RETURN(0)
update MSP_WEB_DELEGATIONS 
   set WRES_ID_DELEGATEE = @p1 
 where WRES_ID_DELEGATEE = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MergeUserDelegatee TO MSProjectServerRole
GO



/* Query #17702 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MergeUserDelegator
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_DELEGATIONS set WRES_ID_DELEGATOR =@p1 where WRES_ID_DELEGATOR =@p0 RETURN(0)
update MSP_WEB_DELEGATIONS 
   set WRES_ID_DELEGATOR = @p1 
 where WRES_ID_DELEGATOR = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MergeUserDelegator TO MSProjectServerRole
GO



/* Query #17703 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MergeUserAssignmentTeamLead
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_ASSIGNMENTS set WRES_ID_TEAM_LEAD=@p1 where WRES_ID_TEAM_LEAD=@p0 RETURN(0)
update MSP_WEB_ASSIGNMENTS 
   set WRES_ID_TEAM_LEAD = @p1 
 where WRES_ID_TEAM_LEAD = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MergeUserAssignmentTeamLead TO MSProjectServerRole
GO



/* Query #17704 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MergeUserRulesManager
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_MGR_RULES set WRES_ID_MGR=@p1 where WRES_ID_MGR=@p0 RETURN(0)
update MSP_WEB_MGR_RULES 
   set WRES_ID_MGR = @p1 
 where WRES_ID_MGR = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MergeUserRulesManager TO MSProjectServerRole
GO



/* Query #17705 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_MergeUserRulesListItem
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_MGR_RULES_LISTS set ITEM_ID=@p1 where (ITEM_TYPE=1 or ITEM_TYPE=2) and ITEM_ID=@p0 RETURN(0)
update MSP_WEB_MGR_RULES_LISTS 
   set ITEM_ID = @p1 
 where (ITEM_TYPE = 1 
            or ITEM_TYPE = 2) 
   and ITEM_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_MergeUserRulesListItem TO MSProjectServerRole
GO


/* Query #17706 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssn
AS
Delete
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL))
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssn TO MSProjectServerRole
GO


/* Query #17707 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssn
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssn TO MSProjectServerRole
GO


/* Query #17708 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnForResId
   @p0 INT
AS
Delete 
  From MSP_WEB_TRANSACTIONS 
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnForResId TO MSProjectServerRole
GO


/* Query #17709 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnForResId
   @p0 INT
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and WRES_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnForResId TO MSProjectServerRole
GO


/* Query #17710 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnOlderThan
   @p0 DATETIME
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnOlderThan TO MSProjectServerRole
GO


/* Query #17711 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnOlderThan
   @p0 DATETIME
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnOlderThan TO MSProjectServerRole
GO


/* Query #17712 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnOlderThanForResId TO MSProjectServerRole
GO


/* Query #17713 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnOlderThanForResId
   @p0 DATETIME,
   @p1 INT
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_FINISH_DATE < @p0 
                       and WRES_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnOlderThanForResId TO MSProjectServerRole
GO


/* Query #17714 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnSentBtw TO MSProjectServerRole
GO


/* Query #17715 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnSentBtw
   @p0 DATETIME,
   @p1 DATETIME
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnSentBtw TO MSProjectServerRole
GO



/* Query #17716 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1 
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnSentBtwForResId TO MSProjectServerRole
GO


/* Query #17717 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnSentBtwForResId
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where (WNWRK_ID = -1 
                        or WNWRK_ID is NULL) 
                       and ASSN_REM_WORK = 0 
                       and ASSN_START_DATE >= @p0 
                       and ASSN_FINISH_DATE < @p1+1
                       and WRES_ID = @p2)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForCompletedAssnSentBtwForResId TO MSProjectServerRole
GO


/* Query #17718 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnForProjIDs
   @p0 NTEXT
AS
Delete 
  From MSP_WEB_TRANSACTIONS
 where WASSN_ID in (Select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS
                     where (WNWRK_ID=-1 or WNWRK_ID is NULL)
                       and WPROJ_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p0))
                   )
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTransactionsForAssnForProjIDs TO MSProjectServerRole
GO



/* Query #18000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllResourcesIgnoreEnabledFlag
AS
Select WRES_ID,RES_NAME From MSP_WEB_RESOURCES RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllResourcesIgnoreEnabledFlag TO MSProjectServerRole
GO



/* Query #30000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetViewFavorites
   @p0 INT,
   @p1 INT
AS
--Select WVIEW_FAV_ID, WVIEW_FAV_NAME, WVIEW_FAV_URL From MSP_WEB_VIEW_FAVORITES Where WRES_ID=@p0 and WVIEW_TYPE=@p1 Order By WVIEW_FAV_NAME RETURN
Select WVIEW_FAV_ID, 
       WVIEW_FAV_NAME, 
       WVIEW_FAV_URL 
  From MSP_WEB_VIEW_FAVORITES 
 Where WRES_ID = @p0 
   and WVIEW_TYPE = @p1 
 Order By WVIEW_FAV_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetViewFavorites TO MSProjectServerRole
GO



/* Query #30001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetColumnOrder
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Select WVIEW_FAV_COLUMN_ORDER, WVIEW_FAV_AUTOFILTER From MSP_WEB_VIEW_FAVORITES Where WRES_ID=@p0 and WVIEW_TYPE=@p1 and WVIEW_FAV_ID=@p2 RETURN
Select WVIEW_FAV_COLUMN_ORDER, 
			 WVIEW_FAV_NAME,
       WVIEW_FAV_AUTOFILTER 
  From MSP_WEB_VIEW_FAVORITES 
 Where WRES_ID = @p0 
   and WVIEW_TYPE = @p1 
   and WVIEW_FAV_ID = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetColumnOrder TO MSProjectServerRole
GO



/* Query #30002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyViewFavorites
AS
--Select * From MSP_WEB_VIEW_FAVORITES Where WVIEW_FAV_ID=-1 RETURN
Select * 
  From MSP_WEB_VIEW_FAVORITES WITH (READPAST) 
 Where WVIEW_FAV_ID = -1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyViewFavorites TO MSProjectServerRole
GO



/* Query #30004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_RenameViewFavorite
   @p0 NVARCHAR(50),
   @p1 INT,
   @p2 INT
AS
--Update MSP_WEB_VIEW_FAVORITES Set WVIEW_FAV_NAME=@p0 where WVIEW_FAV_ID=@p1 and WRES_ID=@p2 RETURN(0)
Update MSP_WEB_VIEW_FAVORITES 
   Set WVIEW_FAV_NAME = @p0 
 where WVIEW_FAV_ID = @p1 
   and WRES_ID = @p2
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_RenameViewFavorite TO MSProjectServerRole
GO



/* Query #30005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjFavorites
   @p0 INT,
   @p1 INT
AS
--Select WVF.WVIEW_FAV_ID, WVF.WPROJ_ID, WVF.WVIEW_FAV_NAME, WVF.WVIEW_FAV_URL, WP.PROJ_NAME From MSP_WEB_VIEW_FAVORITES WVF, MSP_WEB_PROJECTS WP Where WVF.WRES_ID=@p0 and WVF.WVIEW_TYPE=@p1 and WVF.WPROJ_ID=WP.WPROJ_ID Order By WP.PROJ_NAME, WVF.WVIEW_FAV_NAME RETURN
Select WVF.WVIEW_FAV_ID, 
       WVF.WPROJ_ID, 
       WVF.WVIEW_FAV_NAME, 
       WVF.WVIEW_FAV_URL, 
       WP.PROJ_NAME 
  From MSP_WEB_VIEW_FAVORITES WVF, 
       MSP_WEB_PROJECTS WP 
 Where WVF.WRES_ID = @p0 
   and WVF.WVIEW_TYPE = @p1 
   and WVF.WPROJ_ID = WP.WPROJ_ID 
 Order By WP.PROJ_NAME, 
          WVF.WVIEW_FAV_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjFavorites TO MSProjectServerRole
GO



/* Query #30006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllFavorites
   @p0 INT
AS
--Select WVF.WVIEW_FAV_ID, WVF.WVIEW_TYPE, WVF.WPROJ_ID, WVF.WVIEW_FAV_NAME, WVF.WVIEW_FAV_URL, WP.PROJ_NAME From MSP_WEB_VIEW_FAVORITES WVF Left Join MSP_WEB_PROJECTS WP On WVF.WPROJ_ID=WP.WPROJ_ID Where WVF.WRES_ID=@p0 Order By WP.PROJ_NAME, WVF.WVIEW_FAV_NAME RETURN
Select WVF.WVIEW_FAV_ID, 
       WVF.WVIEW_TYPE, 
       WVF.WPROJ_ID, 
       WVF.WVIEW_FAV_NAME, 
       WVF.WVIEW_FAV_URL, 
       WP.PROJ_NAME 
  From MSP_WEB_VIEW_FAVORITES WVF 
       Left Join MSP_WEB_PROJECTS WP 
         On WVF.WPROJ_ID = WP.WPROJ_ID 
 Where WVF.WRES_ID = @p0 
 Order By WP.PROJ_NAME, 
          WVF.WVIEW_FAV_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllFavorites TO MSProjectServerRole
GO



/* Query #30007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEmptyWebProjects
AS
Select * From MSP_WEB_PROJECTS WITH (READPAST) Where WPROJ_ID=-1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEmptyWebProjects TO MSProjectServerRole
GO



/* Query #30008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetPriorityFieldInfoID
   @p0 NVARCHAR(255)
AS
--Select * From MSP_WEB_WORKGROUP_FIELDS_INFO Where FIELD_ID=1073741849 and CUSTFIELD_NAME=@p0 RETURN
Select * 
  From MSP_WEB_WORKGROUP_FIELDS_INFO 
 Where FIELD_ID = 1073741849 
   and CUSTFIELD_NAME = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetPriorityFieldInfoID TO MSProjectServerRole
GO


/* Query #30015 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTasklistTaskFromWebAssignments
   @p0 INT,
   @p1 INT
AS
--Delete From MSP_WEB_ASSIGNMENTS Where WASSN_ID=@p0 and WRES_ID_MGR=@p1 RETURN(0)
Delete 
  From MSP_WEB_ASSIGNMENTS 
 Where WASSN_ID = @p0 
   and WRES_ID_MGR = @p1
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTasklistTaskFromWebAssignments TO MSProjectServerRole
GO



/* Query #30016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTasklistTaskFromWorkGroupFields
   @p0 INT,
   @p1 INT
AS
--Delete From MSP_WEB_WORKGROUP_FIELDS Where WASSN_ID=@p0 and WASSN_ID in (Select WA.WASSN_ID From MSP_WEB_ASSIGNMENTS WA Where WA.WASSN_ID=@p0 and WA.WRES_ID_MGR=@p1) RETURN(0)
Delete 
  From MSP_WEB_WORKGROUP_FIELDS 
 Where WASSN_ID = @p0 
   and WASSN_ID in (Select WA.WASSN_ID 
                      From MSP_WEB_ASSIGNMENTS WA 
                     Where WA.WASSN_ID = @p0 
                       and WA.WRES_ID_MGR = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTasklistTaskFromWorkGroupFields TO MSProjectServerRole
GO



/* Query #30017 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjIDProjectNameFromMyTaskLists
   @p0 INT
AS
--Select WPROJ_ID, PROJ_NAME, WPROJ_SCOPE From MSP_WEB_PROJECTS Where WPROJ_IS_NONWORKING=0 and WRES_ID=@p0 and WPROJ_TYPE=3 Order By PROJ_NAME RETURN
Select WPROJ_ID, 
       PROJ_NAME, 
       WPROJ_SCOPE 
  From MSP_WEB_PROJECTS 
 Where WPROJ_IS_NONWORKING = 0 
   and WRES_ID = @p0 
   and WPROJ_TYPE = 3
 Order By PROJ_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjIDProjectNameFromMyTaskLists TO MSProjectServerRole
GO



/* Query #30018 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ChangeTLOptionsInWebProjects
   @p0 NVARCHAR(255),
   @p1 TINYINT,
   @p2 INT,
   @p3 INT,
   @p4 INT
AS
--Update MSP_WEB_PROJECTS Set PROJ_NAME=@p0, WPROJ_SCOPE=@p1, WRES_ID=@p2 where WPROJ_ID=@p3 and WRES_ID=@p4 RETURN(0)
Update MSP_WEB_PROJECTS 
   Set PROJ_NAME = @p0, 
       WPROJ_SCOPE = @p1, 
       WRES_ID = @p2 
 where WPROJ_ID = @p3 
   and WRES_ID = @p4
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ChangeTLOptionsInWebProjects TO MSProjectServerRole
GO



/* Query #30019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ChangeTLOptionsInWebAssignments
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Update MSP_WEB_ASSIGNMENTS Set WRES_ID_MGR=@p0 where WPROJ_ID=@p1 and WRES_ID_MGR=@p2 RETURN(0)
Update MSP_WEB_ASSIGNMENTS 
   Set WRES_ID_MGR = @p0 
 where WPROJ_ID = @p1 
   and WRES_ID_MGR = @p2
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ChangeTLOptionsInWebAssignments TO MSProjectServerRole
GO



/* Query #30020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTLFromWebProjects
   @p0 INT,
   @p1 INT
AS
--Delete From MSP_WEB_PROJECTS Where WPROJ_ID=@p0 and WRES_ID=@p1 RETURN(0)
Delete 
  From MSP_WEB_PROJECTS 
 Where WPROJ_ID = @p0 
   and WRES_ID = @p1
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTLFromWebProjects TO MSProjectServerRole
GO



/* Query #30021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteTLFromWebAssignments
   @p0 INT,
   @p1 INT
AS
--Delete From MSP_WEB_ASSIGNMENTS Where WPROJ_ID=@p0 and WRES_ID_MGR=@p1 RETURN(0)
Delete 
  From MSP_WEB_ASSIGNMENTS 
 Where WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteTLFromWebAssignments TO MSProjectServerRole
GO



/* Query #35001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetExistingTaskUpdateTrans
   @p0 INT
AS
--SELECT WTRANS_ID,WTRANS_TYPE,WTRANS_ACTION,WTRANS_STATE,WTRANS_DATE FROM MSP_WEB_TRANSACTIONS WHERE WASSN_ID=@p0 and (WTRANS_TYPE=2 or WTRANS_TYPE=0) and WTRANS_STATE<3 RETURN
SELECT WTRANS_ID, 
       WTRANS_TYPE, 
       WTRANS_ACTION, 
       WTRANS_STATE, 
       WTRANS_DATE,
	   WRES_ID_TRANS_SENDER,
	   WTRANS_ADJUST,
	   WASSN_ID,
	   WDELEG_ID
  FROM MSP_WEB_TRANSACTIONS 
 WHERE WASSN_ID = @p0 
   and (WTRANS_TYPE = 2 
            or WTRANS_TYPE = 0) 
   and WTRANS_STATE < 3
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetExistingTaskUpdateTrans TO MSProjectServerRole
GO



/* Query #35002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ModifyTaskUpdateTransDate
   @p0 INT,
   @p1 DATETIME
AS
--UPDATE MSP_WEB_TRANSACTIONS SET WTRANS_DATE=@p1,WTRANS_ACTION=0,WTRANS_STATE=0 WHERE WTRANS_ID=@p0 RETURN(0)
UPDATE MSP_WEB_TRANSACTIONS 
   SET WTRANS_DATE = @p1, 
       WTRANS_ACTION = 0, 
       WTRANS_STATE = 0 
 WHERE WTRANS_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ModifyTaskUpdateTransDate TO MSProjectServerRole
GO


/* Query #35004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetRejectedTasks
   @p0 INT
AS
SELECT WWA.WPRD_START_DATE,WWA.WPRD_FINISH_DATE,WWA.WASSN_ID,WA.WPROJ_ID, WP.PROJ_NAME, WWA.WRES_ID,WWA.WAPPROVAL_NOTIFICATION_SENT
  FROM MSP_WEB_WORK_APPROVAL WWA INNER JOIN MSP_WEB_ASSIGNMENTS WA ON (WA.WASSN_ID = WWA.WASSN_ID)
       INNER JOIN MSP_WEB_PROJECTS WP ON (WP.WPROJ_ID = WA.WPROJ_ID)
 WHERE WWA.WRES_ID in (
	    -- Permission 212: Approve timesheet permission
            select WRES_ID from MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p0, 212, -1)
       )
      AND WWA.WAPPROVAL_NOTIFICATION_SENT = 0
      AND WWA.WAPPROVAL_STATUS = 2
 ORDER BY WWA.WASSN_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetRejectedTasks TO MSProjectServerRole
GO



/* Query #35005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetPendingDelegationTrans
   @p0 INT
AS
--SELECT WA.*,PROJ_NAME,WTRANS_ACTION,WTRANS_STATE,WRES_ID_DELEGATOR,WRES_ID_DELEGATEE FROM MSP_WEB_ASSIGNMENTS WA, MSP_WEB_TRANSACTIONS WT, MSP_WEB_PROJECTS WP, MSP_WEB_DELEGATIONS WD WHERE WA.WASSN_ID=WT.WASSN_ID and WT.WDELEG_ID=WD.WDELEG_ID and WA.WPROJ_ID=WP.WPROJ_ID and WTRANS_TYPE=3 and WTRANS_STATE=0 and WRES_ID_MGR=@p0 and WTRANS_ACTION>0 ORDER BY WA.WPROJ_ID,WRES_ID_DELEGATOR RETURN
SELECT WA.*, 
       PROJ_NAME, 
       WTRANS_ACTION,
       WTRANS_ID, 
       WTRANS_STATE, 
       WRES_ID_DELEGATOR, 
       WRES_ID_DELEGATEE 
  FROM MSP_WEB_ASSIGNMENTS WA, 
       MSP_WEB_TRANSACTIONS WT, 
       MSP_WEB_PROJECTS WP, 
       MSP_WEB_DELEGATIONS WD 
 WHERE WA.WASSN_ID = WT.WASSN_ID 
   and WT.WDELEG_ID = WD.WDELEG_ID 
   and WA.WPROJ_ID = WP.WPROJ_ID 
   and WTRANS_TYPE = 3 
   and WTRANS_STATE = 0 
   and WRES_ID_MGR = @p0 
   and WTRANS_ACTION > 0 
 ORDER BY WA.WPROJ_ID, 
          WRES_ID_DELEGATOR
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetPendingDelegationTrans TO MSProjectServerRole
GO



/* Query #35006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetNonDelegTransStateBasedOnAction
   @p0 INT,
   @p1 INT,
   @p2 DATETIME
AS
--UPDATE MSP_WEB_TRANSACTIONS SET WTRANS_STATE=3,WTRANS_PROJ_UPDATE_DATE=@p2 WHERE WTRANS_STATE<3 and WTRANS_TYPE<3 and WTRANS_ACTION=@p1 and WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA WHERE WRES_ID_MGR=@p0) RETURN(0)
UPDATE MSP_WEB_TRANSACTIONS 
   SET WTRANS_STATE = 3, 
       WTRANS_PROJ_UPDATE_DATE = @p2 
 WHERE WTRANS_STATE < 3 
   and WTRANS_TYPE < 3 
   and WTRANS_ACTION = @p1 
   and WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA 
                     WHERE WRES_ID_MGR = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetNonDelegTransStateBasedOnAction TO MSProjectServerRole
GO



/* Query #35008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateDelegTrans
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_TRANSACTIONS SET WTRANS_STATE=@p1,WTRANS_ACTION=1 WHERE WDELEG_ID=@p0 RETURN(0)
UPDATE MSP_WEB_TRANSACTIONS 
   SET WTRANS_STATE = @p1, 
       WTRANS_ACTION = 1 
 WHERE WDELEG_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateDelegTrans TO MSProjectServerRole
GO



/* Query #35009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDelegTransState
   @p0 INT
AS
--SELECT WTRANS_STATE FROM MSP_WEB_TRANSACTIONS WHERE WDELEG_ID=@p0 RETURN
SELECT WTRANS_STATE 
  FROM MSP_WEB_TRANSACTIONS 
 WHERE WDELEG_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDelegTransState TO MSProjectServerRole
GO



/* Query #35010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetTransactedNewTaskState
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET WASSN_CREATED_BY_RES=@p1 WHERE WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA,MSP_WEB_TRANSACTIONS WT WHERE WA.WASSN_ID=WT.WASSN_ID and WA.WRES_ID_MGR=@p0 and WTRANS_TYPE=2 and WTRANS_ACTION=2 and WTRANS_STATE=0) RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WASSN_CREATED_BY_RES = @p1 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WRES_ID_MGR = @p0 
                       and WTRANS_TYPE = 2 
                       and WTRANS_ACTION = 2 
                       and WTRANS_STATE = 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetTransactedNewTaskState TO MSProjectServerRole
GO



/* Query #35012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetTransRejectTaskDecline
   @p0 INT
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET WASSN_IS_CONFIRMED=1 WHERE WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA,MSP_WEB_TRANSACTIONS WT WHERE WA.WASSN_ID=WT.WASSN_ID and WA.WRES_ID_MGR=@p0 and WTRANS_TYPE=1 and WTRANS_ACTION=2 and WTRANS_STATE=0) RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WASSN_IS_CONFIRMED = 1 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WRES_ID_MGR = @p0 
                       and WTRANS_TYPE = 1 
                       and WTRANS_ACTION = 2 
                       and WTRANS_STATE = 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetTransRejectTaskDecline TO MSProjectServerRole
GO



/* Query #35015 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteGhostAssignsAfterDelegUpdate
   @p0 INT,
   @p1 INT
AS
--DELETE FROM MSP_WEB_ASSIGNMENTS WHERE WASSN_IS_DELEGATED<>0 and MSP_WEB_ASSIGNMENTS.WRES_ID=-1 and WASSN_DELEG_PENDING=0 and WPROJ_ID=@p0 and WRES_ID_MGR=@p1 RETURN(0)
DELETE 
  FROM MSP_WEB_ASSIGNMENTS 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WPROJ_ID = @p0 
                       and WASSN_IS_DELEGATED <> 0 
					   and WA.WRES_ID = -1 
                       and WASSN_DELEG_PENDING = 0  
                       and WT.WTRANS_STATE = 2 
                       and WT.WTRANS_TYPE = 3 
                       and WT.WTRANS_ACTION > 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteGhostAssignsAfterDelegUpdate TO MSProjectServerRole
GO



/* Query #35016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateDelegationFlagForFileID
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET WASSN_IS_DELEGATED=0 WHERE WASSN_IS_DELEGATED<>0 and WASSN_DELEG_PENDING=0 and WPROJ_ID=@p0 and WRES_ID_MGR=@p1 RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WASSN_IS_DELEGATED = 0 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WPROJ_ID = @p0 
                       and WASSN_IS_DELEGATED <> 0 
                       and WASSN_DELEG_PENDING = 0  
                       and WT.WTRANS_STATE > 1 
                       and WT.WTRANS_TYPE = 3 
                       and WT.WTRANS_ACTION > 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateDelegationFlagForFileID TO MSProjectServerRole
GO



/* Query #35017 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateCreatedByResFlagForAssnIDs
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET WASSN_CREATED_BY_RES=0,WASSN_UPDATE_STATUS=0,WASSN_SEND_UPDATE_NEEDED=0,WASSN_ACTUALS_PENDING=0,WASSN_UPDATE_TRACKING_MODE=WASSN_CURRENT_TRACKING_MODE WHERE WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA, MSP_WEB_TRANSACTIONS WT WHERE WA.WASSN_ID=WT.WASSN_ID and WA.WPROJ_ID=@p0 and WA.WRES_ID_MGR=@p1 and WT.WTRANS_STATE=2 and WT.WTRANS_TYPE=2 and WT.WTRANS_ACTION=1) RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WASSN_CREATED_BY_RES = 0, 
       WASSN_UPDATE_STATUS = 0, 
       WASSN_SEND_UPDATE_NEEDED = 0, 
       WASSN_ACTUALS_PENDING = 0, 
       WASSN_UPDATE_TRACKING_MODE = WASSN_CURRENT_TRACKING_MODE 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WPROJ_ID = @p0 
                       and WT.WTRANS_STATE = 2 
                       and WT.WTRANS_TYPE = 2 
                       and WT.WTRANS_ACTION = 1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateCreatedByResFlagForAssnIDs TO MSProjectServerRole
GO



/* Query #35018 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAssnDirtyFlagAndTrackingForAssnId
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET WASSN_UPDATE_STATUS=0,WASSN_SEND_UPDATE_NEEDED=0,WASSN_ACTUALS_PENDING=0,WASSN_UPDATE_TRACKING_MODE=WASSN_CURRENT_TRACKING_MODE WHERE WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA, MSP_WEB_TRANSACTIONS WT WHERE WA.WASSN_ID=WT.WASSN_ID and WA.WPROJ_ID=@p0 and WA.WRES_ID_MGR=@p1 and WT.WTRANS_STATE=2 and WT.WTRANS_TYPE<2 and WT.WTRANS_ACTION=1) RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WASSN_UPDATE_STATUS = 0, 
       WASSN_SEND_UPDATE_NEEDED = 0, 
       WASSN_ACTUALS_PENDING = 0, 
       WASSN_UPDATE_TRACKING_MODE = WASSN_CURRENT_TRACKING_MODE 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WPROJ_ID = @p0 
                       and WT.WTRANS_STATE = 2 
                       and WT.WTRANS_TYPE < 2 
                       and WT.WTRANS_ACTION = 1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAssnDirtyFlagAndTrackingForAssnId TO MSProjectServerRole
GO



/* Query #35019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetTransStateToHistory
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_TRANSACTIONS SET WTRANS_STATE=3 WHERE WTRANS_STATE=2 and WTRANS_ACTION>0 and WASSN_ID in (SELECT WASSN_ID FROM MSP_WEB_ASSIGNMENTS WHERE WRES_ID_MGR=@p1 and WPROJ_ID=@p0) RETURN(0)
UPDATE MSP_WEB_TRANSACTIONS 
   SET WTRANS_STATE = 3 
 WHERE WTRANS_STATE = 2 
   and WTRANS_ACTION > 0 
   and WASSN_ID in (SELECT WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS 
                     WHERE WPROJ_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetTransStateToHistory TO MSProjectServerRole
GO



/* Query #35020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAssnDirtyFlagForActuals
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_WORK SET WWORK_UPDATE_STATUS=0 WHERE WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA, MSP_WEB_TRANSACTIONS WT WHERE WA.WASSN_ID=WT.WASSN_ID and WA.WPROJ_ID=@p0 and WA.WRES_ID_MGR=@p1 and WT.WTRANS_STATE=2 and WT.WTRANS_TYPE<3 and WT.WTRANS_ACTION=1) RETURN(0)
UPDATE MSP_WEB_WORK 
   SET WWORK_UPDATE_STATUS = 0 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WPROJ_ID = @p0 
                       and WT.WTRANS_STATE = 2 
                       and WT.WTRANS_TYPE < 3 
                       and WT.WTRANS_ACTION = 1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAssnDirtyFlagForActuals TO MSProjectServerRole
GO



/* Query #35021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAssnDirtyFlagForCustomFields
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_WORKGROUP_FIELDS SET WWORKGRP_UPDATE_STATUS=0 WHERE WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA, MSP_WEB_TRANSACTIONS WT WHERE WA.WASSN_ID=WT.WASSN_ID and WA.WPROJ_ID=@p0 and WA.WRES_ID_MGR=@p1 and WT.WTRANS_STATE=2 and WT.WTRANS_TYPE<3 and WT.WTRANS_ACTION=1) RETURN(0)
UPDATE MSP_WEB_WORKGROUP_FIELDS 
   SET WWORKGRP_UPDATE_STATUS = 0 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WPROJ_ID = @p0 
                       and WT.WTRANS_STATE = 2 
                       and WT.WTRANS_TYPE < 3 
                       and WT.WTRANS_ACTION = 1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAssnDirtyFlagForCustomFields TO MSProjectServerRole
GO



/* Query #35022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMaxMinActualPeriodForTrans
   @p0 INT
AS
--SELECT MIN(WWORK_START) AS WWORK_START,MAX(WWORK_FINISH) AS WWORK_FINISH FROM MSP_WEB_WORK,MSP_WEB_ASSIGNMENTS WA,MSP_WEB_TRANSACTIONS WHERE MSP_WEB_WORK.WASSN_ID=WA.WASSN_ID and WA.WASSN_ID=MSP_WEB_TRANSACTIONS.WASSN_ID and WRES_ID_MGR=@p0 and WWORK_TYPE>0 and WWORK_UPDATE_STATUS>0 and WTRANS_STATE<3 RETURN
SELECT MIN(WWORK_START) AS WWORK_START, 
       MAX(WWORK_FINISH) AS WWORK_FINISH 
  FROM MSP_WEB_WORK, 
       MSP_WEB_ASSIGNMENTS WA, 
       MSP_WEB_TRANSACTIONS 
 WHERE MSP_WEB_WORK.WASSN_ID = WA.WASSN_ID 
   and WA.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID 
   and WRES_ID_MGR = @p0 
   and WWORK_TYPE > 0 
   and WWORK_UPDATE_STATUS > 0 
   and WTRANS_STATE < 3
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMaxMinActualPeriodForTrans TO MSProjectServerRole
GO



/* Query #35023 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAssnProjForTransRejectNotifications
   @p0 INT
AS
--SELECT WA.WASSN_ID,WA.WRES_ID,WA.WPROJ_ID,PROJ_NAME,WTRANS_TYPE FROM MSP_WEB_ASSIGNMENTS WA,MSP_WEB_PROJECTS WP,MSP_WEB_TRANSACTIONS WT WHERE WA.WPROJ_ID=WP.WPROJ_ID and WA.WASSN_ID=WT.WASSN_ID and WRES_ID_MGR=@p0 and WTRANS_TYPE<3 and WTRANS_ACTION=2 and WTRANS_STATE<3 ORDER BY WTRANS_TYPE,WA.WPROJ_ID,WA.WRES_ID RETURN
SELECT WA.WASSN_ID, 
       WA.WRES_ID, 
       WA.WPROJ_ID, 
       PROJ_NAME, 
       WTRANS_TYPE,
	   WRES_ID_TRANS_SENDER
  FROM MSP_WEB_ASSIGNMENTS WA, 
       MSP_WEB_PROJECTS WP, 
       MSP_WEB_TRANSACTIONS WT 
 WHERE WA.WPROJ_ID = WP.WPROJ_ID 
   and WA.WASSN_ID = WT.WASSN_ID 
   and WRES_ID_MGR = @p0 
   and WTRANS_TYPE < 3 
   and WTRANS_ACTION = 2 
   and WTRANS_STATE < 3 
 ORDER BY WTRANS_TYPE, 
          WA.WPROJ_ID, 
          WA.WRES_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAssnProjForTransRejectNotifications TO MSProjectServerRole
GO



/* Query #35026 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteOutdatedTransHistory
   @p0 INT,
   @p1 DATETIME
AS
--DELETE FROM MSP_WEB_TRANSACTIONS WHERE WTRANS_PROJ_UPDATE_DATE<@p1 and WTRANS_STATE=3 and WASSN_ID in (SELECT WA.WASSN_ID FROM MSP_WEB_ASSIGNMENTS WA WHERE WA.WRES_ID_MGR=@p0) RETURN(0)
DELETE 
  FROM MSP_WEB_TRANSACTIONS 
 WHERE WTRANS_PROJ_UPDATE_DATE < @p1 
   and WTRANS_STATE = 3 
   and WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA 
                     WHERE WA.WRES_ID_MGR = @p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteOutdatedTransHistory TO MSProjectServerRole
GO



/* Query #35028 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNumberOfPendingTransForMgr
   @p0 INT
AS
--SELECT COUNT(WTRANS_ID) AS TNumTrans from MSP_WEB_TRANSACTIONS INNER JOIN MSP_WEB_ASSIGNMENTS ON MSP_WEB_TRANSACTIONS.WASSN_ID=MSP_WEB_ASSIGNMENTS.WASSN_ID WHERE WTRANS_STATE<2 and WRES_ID_MGR=@p0 RETURN
SELECT COUNT(WTRANS_ID) AS TNumTrans 
  from MSP_WEB_TRANSACTIONS 
       INNER JOIN MSP_WEB_ASSIGNMENTS 
          ON MSP_WEB_TRANSACTIONS.WASSN_ID = MSP_WEB_ASSIGNMENTS.WASSN_ID 
 WHERE WTRANS_STATE < 2 
   and WRES_ID_MGR = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNumberOfPendingTransForMgr TO MSProjectServerRole
GO


/* Query #35029 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetRuleForRuleIDMgrID
   @p0 INT,
   @p1 INT
AS
SELECT WRULE_ID
FROM MSP_WEB_MGR_RULES
WHERE WRULE_ID=@p1 and WRES_ID_MGR=@p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetRuleForRuleIDMgrID TO MSProjectServerRole
GO



/* Query #35030 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetTransRejectTaskUpdate
   @p0 INT
AS
UPDATE MSP_WEB_ASSIGNMENTS 
   SET WASSN_ACTUALS_PENDING = 2 
 WHERE WASSN_ID in (SELECT WA.WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS WA, 
                           MSP_WEB_TRANSACTIONS WT 
                     WHERE WA.WASSN_ID = WT.WASSN_ID 
                       and WA.WRES_ID_MGR = @p0 
                       and WTRANS_TYPE = 0 
                       and WTRANS_ACTION = 2 
                       and WTRANS_STATE = 0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetTransRejectTaskUpdate TO MSProjectServerRole
GO



/* Query #35031 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllFromTaskUIDCheckPerm
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
Select WP.WPROJ_ID,WP.WRES_ID,WPROJ_TRACKING_METHOD,TaskName,TaskStart,TaskFinish,TaskWork,TaskID,TaskOutlineNumber
From 
MSP_VIEW_PROJ_TASKS_STD PTS
INNER JOIN MSP_WEB_PROJECTS WP ON PTS.WPROJ_ID=WP.WPROJ_ID
INNER JOIN dbo.MSP_WEB_FN_SEC_GetAllProjectsResCanViewByViewID(@p0,509,-1,1) PL ON WP.WPROJ_ID=PL.WPROJ_ID
Where WP.WPROJ_ID=@p1 and TaskUniqueID=@p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllFromTaskUIDCheckPerm TO MSProjectServerRole
GO



/* Query #35032 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_CreateSummariesAndNewAssnFromOutlineNumbers
   @resID INT,
   @taskname NVARCHAR(255),
   @projID INT,
   @str NTEXT,
   @TaskUniqueID INT,
   @TaskID INT,
   @start DATETIME,
   @finish DATETIME,
   @work INT,
   @newassn INT,
   @sendupdate INT,
   @notestatus INT,
   @comments NTEXT

AS

declare @strlen int, @curpos int, @val nvarchar(1000), @nextcomma int, @parentUID int, @parentAID int, @taskUID int
set @parentUID = -1
set @parentAID = -1
set @strlen = datalength(@str)
set @curpos = 0

-- For each token, load it into the table
while @curpos <= @strlen
begin
	-- get the next token
	set @nextcomma = dbo.MSP_WEB_FN_charindex_ex(',', @str, @curpos)
	if @nextcomma = 0
		set @nextcomma = @strlen + 1
	--select @nextcomma as '@nextcomma', @curpos as '@curpos', substring(@str,@curpos,@nextcomma - @curpos) as 'Substring'
	set @val = substring(@str,@curpos,@nextcomma - @curpos)
	-- load the table variable

	-- check for existence of summary assignment and create if neccessary
	set @taskUID = (select TaskUniqueID from MSP_VIEW_PROJ_TASKS_STD where WPROJ_ID=@projID and TaskOutlineNumber like @val)
	if (not exists (select WASSN_ID from MSP_WEB_ASSIGNMENTS where TASK_UID=@taskUID and WRES_ID=@resID and TASK_IS_SUMMARY<>0 and WPROJ_ID=@projID))
	begin
		insert into MSP_WEB_ASSIGNMENTS (WRES_ID,WASSN_PARENT_ID,WPROJ_ID,WRES_ID_MGR,ASSN_UID,TASK_ID,TASK_UID,TASK_UID_SUMMARY,TASK_NAME,ASSN_START_DATE,ASSN_FINISH_DATE,ASSN_WORK,ASSN_REM_WORK,TASK_IS_SUMMARY,WASSN_IS_CONFIRMED)
			select @resID,@parentAID,@projID,WP.WRES_ID,-1,TaskID,@taskUID,@parentUID,TaskName,TaskStart,TaskFinish,TaskWork,TaskRemainingWork,1,1
			from MSP_VIEW_PROJ_TASKS_STD PTS INNER JOIN MSP_WEB_PROJECTS WP ON PTS.WPROJ_ID=WP.WPROJ_ID 
			where PTS.WPROJ_ID=@projID and TaskUniqueID = @taskUID
	end

	-- set the parent ID's for the next iteration
	set @parentUID = @taskUID 
	set @parentAID = (select WASSN_ID from MSP_WEB_ASSIGNMENTS where TASK_UID=@taskUID and WRES_ID=@resID and TASK_IS_SUMMARY<>0 and WPROJ_ID=@projID)


	-- increment to the next position, and handle the last token
	set @curpos = @nextcomma + 1
end

insert into MSP_WEB_ASSIGNMENTS (WRES_ID,WPROJ_ID,WRES_ID_MGR,WASSN_CURRENT_TRACKING_MODE,
                                 WASSN_PARENT_ID,ASSN_UID,TASK_UID,TASK_ID,TASK_UID_SUMMARY,
								 TASK_NAME,ASSN_START_DATE,ASSN_FINISH_DATE,ASSN_WORK,ASSN_REM_WORK,WASSN_PCT_COMP,
								 TASK_IS_SUMMARY,WASSN_IS_CONFIRMED,WASSN_MGR_UPDATED,
								 WASSN_CREATED_BY_RES,WASSN_ASSIGNED_TO_EXISTING,WASSN_DELETED_IN_PROJ,
								 WASSN_SEND_UPDATE_NEEDED,WASSN_NOTE_STATUS,WASSN_COMMENTS)

select @resID,@projID,WP.WRES_ID,WPROJ_TRACKING_METHOD,
       @parentAID,-1,@TaskUniqueID,@TaskID,@parentUID,
	   @taskname,@start,@finish,@work,@work,0,
	   0,1,0,
	   1,@newassn,0,
	   @sendupdate,@notestatus,@comments
from MSP_WEB_PROJECTS WP
where WPROJ_ID=@projID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_CreateSummariesAndNewAssnFromOutlineNumbers TO MSProjectServerRole
GO



/* Query #46000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetFileIDProjectNameFromFilesTaskList
   @p0 INT
AS
BEGIN

Select WP.WPROJ_ID, 
       PROJ_NAME, 
       WRES_ID, 
       WPROJ_TYPE,
       WPROJ_TRACKING_METHOD 
  From MSP_WEB_PROJECTS WP
 Where WPROJ_IS_NONWORKING = 0 
   and WPROJ_ADMINPROJECT = 0
   and WPROJ_ID = WPROJ_DEFAULT_WPROJ_ID
   and (
	   (WPROJ_TYPE = 3 and WRES_ID = @p0)
    or (WPROJ_TYPE <> 3 and WP.WPROJ_ID in (select WPROJ_ID from dbo.MSP_WEB_FN_SEC_GetAllProjectsResCanViewByViewID(@p0,213,-1,1)))
	   )
Order By PROJ_NAME

RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetFileIDProjectNameFromFilesTaskList TO MSProjectServerRole
GO


/* Query #46001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectsOnlyForTLOwner
   @p0 INT
AS
Select WPROJ_ID, 
       PROJ_NAME, 
       WRES_ID, 
       WPROJ_TYPE,
       WPROJ_TRACKING_METHOD 
  From MSP_WEB_PROJECTS 
 Where WPROJ_IS_NONWORKING = 0 
   and WPROJ_TYPE = 3 
   and WRES_ID = @p0 
 Order By PROJ_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectsOnlyForTLOwner TO MSProjectServerRole
GO



/* Query #46002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectIDNameForNewAssn
   @p0 INT
AS
SELECT WP.WPROJ_ID, 
       PROJ_NAME
  FROM MSP_WEB_PROJECTS WP 
       INNER JOIN dbo.MSP_WEB_FN_SEC_GetAllProjectsResCanViewByViewID(@p0,213,-1,1) PL ON WP.WPROJ_ID=PL.WPROJ_ID
 WHERE WPROJ_IS_NONWORKING = 0 
   and WP.WPROJ_ID = WPROJ_DEFAULT_WPROJ_ID
   and WPROJ_TYPE in (1,2)
 ORDER BY PROJ_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectIDNameForNewAssn TO MSProjectServerRole
GO



/* Query #65000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SRP_GetAllOverdueStatusReports
   @p0 DATETIME
AS
--select MSP_WEB_STATUS_REQUESTS.WSR_ID, MSP_WEB_STATUS_REQUESTS.WRES_ID_RECEIVER, MSP_WEB_STATUS_REQUESTS.WDUE_ON from MSP_WEB_STATUS_REQUESTS, MSP_WEB_STATUS_REPORTS where WREQ_IS_ENABLED<>0 and WREQ_IS_SENT<>0 and WREPORT_IS_ENABLED<>0 and MSP_WEB_STATUS_REQUESTS.WSR_ID = MSP_WEB_STATUS_REPORTS.WSR_ID and WDUE_ON<@p0 order by MSP_WEB_STATUS_REQUESTS.WSR_ID RETURN
select MSP_WEB_STATUS_REQUESTS.WSR_ID, 
       MSP_WEB_STATUS_REQUESTS.WRES_ID_RECEIVER, 
       MSP_WEB_STATUS_REQUESTS.WDUE_ON 
  from MSP_WEB_STATUS_REQUESTS, 
       MSP_WEB_STATUS_REPORTS 
 where WREQ_IS_ENABLED <> 0 
   and WREQ_IS_SENT <> 0 
   and WREPORT_IS_ENABLED <> 0 
   and MSP_WEB_STATUS_REQUESTS.WSR_ID = MSP_WEB_STATUS_REPORTS.WSR_ID 
   and WDUE_ON < @p0 
 order by MSP_WEB_STATUS_REQUESTS.WSR_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SRP_GetAllOverdueStatusReports TO MSProjectServerRole
GO



/* Query #65001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSelfReminders
   @p0 INT
AS
--select RM.* from MSP_WEB_REMINDERS RM, MSP_WEB_REMINDER_TYPES OP where RM.WRMND_OWNER_ID=@p0 and RM.WRMND_TYPE_ID=OP.WRMND_TYPE_ID and OP.WRMND_IS_SELF<>0 RETURN
select RM.* 
  from MSP_WEB_REMINDERS RM, 
       MSP_WEB_REMINDER_TYPES OP 
 where RM.WRMND_OWNER_ID = @p0 
   and RM.WRMND_TYPE_ID = OP.WRMND_TYPE_ID 
   and OP.WRMND_IS_SELF <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSelfReminders TO MSProjectServerRole
GO



/* Query #65002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMgrReminders
   @p0 INT
AS
--select RM.* from MSP_WEB_REMINDERS RM, MSP_WEB_REMINDER_TYPES OP where RM.WRMND_OWNER_ID=@p0 and RM.WRMND_TYPE_ID=OP.WRMND_TYPE_ID and OP.WRMND_IS_SELF=0 RETURN
select RM.* 
  from MSP_WEB_REMINDERS RM, 
       MSP_WEB_REMINDER_TYPES OP 
 where RM.WRMND_OWNER_ID = @p0 
   and RM.WRMND_TYPE_ID = OP.WRMND_TYPE_ID 
   and OP.WRMND_IS_SELF = 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMgrReminders TO MSProjectServerRole
GO



/* Query #65004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotifications
   @p0 INT
AS
--select * from MSP_WEB_NOTIFICATIONS where WNTFY_OWNER_ID=@p0 RETURN
select * 
  from MSP_WEB_NOTIFICATIONS 
 where WNTFY_OWNER_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotifications TO MSProjectServerRole
GO



/* Query #65010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_DeleteTemp
AS
--delete from MSP_WEB_REMINDERS_TEMP where WRMND_MSG_SENT<>0 RETURN(0)
delete 
  from MSP_WEB_REMINDERS_TEMP 
 where WRMND_MSG_SENT <> 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_DeleteTemp TO MSProjectServerRole
GO



/* Query #65011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_GetReminderTemp
AS
--select WRMND_ID_RECEIVER, WRMND_TABLE_ID, WRES_EMAIL, WRES_EMAIL_LANGUAGE, WRMND_MSG_SENT, WRMND_MESSAGE from MSP_WEB_REMINDERS_TEMP, MSP_WEB_RESOURCES where WMSG_SENT<>0 and WRMND_ID_RECEIVER=WRES_ID RETURN
select WRMND_ID_RECEIVER, 
       WRMND_TABLE_ID, 
       WRES_EMAIL, 
       WRES_EMAIL_LANGUAGE,
       WRMND_MSG_SENT,
       WRMND_MESSAGE 
  from MSP_WEB_REMINDERS_TEMP, 
       MSP_WEB_RESOURCES 
 where WRMND_MSG_SENT = 0 
   and WRMND_ID_RECEIVER = WRES_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_GetReminderTemp TO MSProjectServerRole
GO



/* Query #65012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_AllReminders
   @p0 DATETIME
AS
--select RM.*, OP.WRMND_TABLE_ID, OP.WRMND_IS_SELF, RS.RES_NAME from MSP_WEB_REMINDERS RM, MSP_WEB_REMINDER_TYPES OP, MSP_WEB_RESOURCES RS where WRMND_IS_ENABLED<>0 and WRMND_NEXT_UPDATE<=@p0 and RM.WRMND_TYPE_ID=OP.WRMND_TYPE_ID and RM.WRMND_OWNER_ID=RS.WRES_ID RETURN
select RM.*, 
       OP.WRMND_TABLE_ID, 
       OP.WRMND_IS_SELF, 
       RS.RES_NAME 
  from MSP_WEB_REMINDERS RM, 
       MSP_WEB_REMINDER_TYPES OP, 
       MSP_WEB_RESOURCES RS 
 where WRMND_IS_ENABLED <> 0 
   and WRMND_NEXT_UPDATE <= @p0 
   and RM.WRMND_TYPE_ID = OP.WRMND_TYPE_ID 
   and RM.WRMND_OWNER_ID = RS.WRES_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_AllReminders TO MSProjectServerRole
GO



/* Query #65019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_ReminderTemp
   @p0 INT,
   @p1 INT
AS
--select * from MSP_WEB_REMINDERS_TEMP where WRMND_ID_RECEIVER=@p0 and WRMND_TABLE_ID=@p1 RETURN
select * 
  from MSP_WEB_REMINDERS_TEMP 
 where WRMND_ID_RECEIVER = @p0 
   and WRMND_TABLE_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_ReminderTemp TO MSProjectServerRole
GO



/* Query #65020 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_GetProjectName
   @p0 INT
AS
--select PROJ_NAME from MSP_WEB_PROJECTS where WPROJ_ID=@p0 RETURN
select PROJ_NAME 
  from MSP_WEB_PROJECTS 
 where WPROJ_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_GetProjectName TO MSProjectServerRole
GO



/* Query #65021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_GetResName
   @p0 INT
AS
--select RES_NAME from MSP_WEB_RESOURCES where WRES_ID=@p0 RETURN
select RES_NAME 
  from MSP_WEB_RESOURCES 
 where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_GetResName TO MSProjectServerRole
GO



/* Query #65022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_GetSRName
   @p0 INT
AS
--select WREPORT_NAME From MSP_WEB_STATUS_REPORTS Where WSR_ID=@p0 and WREPORT_IS_ENABLED<>0 RETURN
select WREPORT_NAME 
  From MSP_WEB_STATUS_REPORTS 
 Where WSR_ID = @p0 
   and WREPORT_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_GetSRName TO MSProjectServerRole
GO



/* Query #65023 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_SetNextUpdate
   @p0 DATETIME,
   @p1 INT,
   @p2 INT
AS
--update MSP_WEB_REMINDERS set WRMND_NEXT_UPDATE=@p0 where WRMND_OWNER_ID=@p1 and WRMND_TYPE_ID=@p2 RETURN(0)
update MSP_WEB_REMINDERS 
   set WRMND_NEXT_UPDATE = @p0 
 where WRMND_OWNER_ID = @p1 
   and WRMND_TYPE_ID = @p2
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_SetNextUpdate TO MSProjectServerRole
GO



/* Query #65024 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_SetMsgSent
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_REMINDERS_TEMP set WRMND_MSG_SENT=1 where WRMND_ID_RECEIVER=@p0 and WRMND_TABLE_ID=@p1 RETURN(0)
update MSP_WEB_REMINDERS_TEMP 
   set WRMND_MSG_SENT = 1 
 where WRMND_ID_RECEIVER = @p0 
   and WRMND_TABLE_ID = @p1
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_SetMsgSent TO MSProjectServerRole
GO



/* Query #65025 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_GetReminderInfo
   @p0 INT
AS
--select * from MSP_WEB_REMINDER_TYPES R where WRMND_TYPE_ID = @p0 RETURN
select * 
  from MSP_WEB_REMINDER_TYPES R 
 where WRMND_TYPE_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_GetReminderInfo TO MSProjectServerRole
GO



/* Query #65026 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_GetReminderSubjects
   @p0 INT
AS
--select CONV_VALUE, CONV_STRING from MSP_WEB_CONVERSIONS where STRING_TYPE_ID=3 and LANG_ID=@p0 and CONV_VALUE in (201, 202, 203, 301, 302, 303) RETURN
select CONV_VALUE, 
       CONV_STRING 
  from MSP_WEB_CONVERSIONS 
 where STRING_TYPE_ID = 3 
   and LANG_ID = @p0 
   and CONV_VALUE in (201, 202, 203, 301, 302, 303)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_GetReminderSubjects TO MSProjectServerRole
GO



/* Query #65028 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SVR_GetReminderString
   @p0 INT,
   @p1 INT
AS
--select CONV_STRING from MSP_WEB_CONVERSIONS where STRING_TYPE_ID=3 and CONV_VALUE=@p0 and LANG_ID=@p1 RETURN
select CONV_STRING 
  from MSP_WEB_CONVERSIONS 
 where STRING_TYPE_ID = 3 
   and CONV_VALUE = @p0 
   and LANG_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SVR_GetReminderString TO MSProjectServerRole
GO



/* Query #65029 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationSubscription
   @p0 INT,
   @p1 INT
AS
--select WNTFY_IS_ENABLED from MSP_WEB_NOTIFICATIONS where WNTFY_OWNER_ID=@p0 and WNTFY_EVENT_ID=@p1 RETURN
select WNTFY_IS_ENABLED 
  from MSP_WEB_NOTIFICATIONS 
 where WNTFY_OWNER_ID = @p0 
   and WNTFY_EVENT_ID = @p1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationSubscription TO MSProjectServerRole
GO



/* Query #65030 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResEmail
   @p0 INT
AS
select 
	WRES_GUID, 
	RES_NAME, 
	WRES_EMAIL, 
	case when WRES_EMAIL_LANGUAGE=0 then WADMIN_DEFAULT_LANGUAGE else WRES_EMAIL_LANGUAGE end 
		as WRES_EMAIL_LANGUAGE 
from 
	MSP_WEB_RESOURCES, 
	MSP_WEB_ADMIN 
where 
	WRES_ID=@p0 

RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResEmail TO MSProjectServerRole
GO



/* Query #65034 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetENInfo
   @p0 INT
AS
select * 
  from MSP_WEB_NOTIFICATION_EVENTS 
 where WNTFY_EVENT_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetENInfo TO MSProjectServerRole
GO

/* Query #65100 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNPESchedule
   @pJobname nvarchar(128)
AS
BEGIN
   EXEC msdb..sp_help_jobschedule @job_name=@pJobname, @schedule_name=@pJobname
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNPESchedule TO MSProjectServerRole
GO

/* Query #65101 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteNPESchedule
   @pJobname nvarchar(128)
AS
BEGIN
   EXEC msdb..sp_delete_job @job_name=@pJobname
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteNPESchedule TO MSProjectServerRole
GO


/* Query #65102 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetNPESchedule
   @pJobname   nvarchar(128),
   @pStartTime int,
   @pCommand   nvarchar(128)
AS
BEGIN
   EXEC msdb..sp_add_job @job_name=@pJobname
   EXEC msdb..sp_add_jobstep @job_name=@pJobname, @step_name=@pJobname, @subsystem=N'CMDEXEC', @command=@pCommand
   EXEC msdb..sp_add_jobschedule @job_name=@pJobname, @name=@pJobname, @freq_type=4, @freq_interval=1, @freq_subday_type=1, @active_start_time=@pStartTime
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetNPESchedule TO MSProjectServerRole
GO


/* Query #65103 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateNPESchedule
   @pJobname   nvarchar(128),
   @pStartTime int
AS
BEGIN
   EXEC msdb..sp_update_jobschedule @job_name=@pJobname, @name=@pJobname, @active_start_time=@pStartTime
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateNPESchedule TO MSProjectServerRole
GO

/* Query #65104 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetNPEScheduledTime
   @p0	INT,
   @p1  DATETIME
AS
BEGIN
   Update MSP_WEB_ADMIN set WADMIN_NPE_SCHEDULED_TIME=@p0, WADMIN_NPE_NEXT_RUN=@p1
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetNPEScheduledTime TO MSProjectServerRole
GO

/* Query #65200 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEntProjectInfoForEPID
   @p0  INT
AS
BEGIN
   select EP.PROJ_PROJECT, 
          EV.VERS_DEFAULT
     from MSP_WEB_PROJECTS WP, 
          MSP_PROJECTS EP, 
          MSP_VERSIONS EV 
    Where WP.PROJ_ID = @p0
      and WP.PROJ_ID = EP.PROJ_ID 
      and EP.PROJ_VERSION = EV.VERS_VERSION
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEntProjectInfoForEPID TO MSProjectServerRole
GO

/* Query #65201 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetEntProjectInfoForEPName
  @p0 NVARCHAR(200)
AS
BEGIN
  -- don't return Template.
  select EP.PROJ_ID
    from MSP_PROJECTS EP,
         MSP_VERSIONS EV
   where lower(EP.PROJ_PROJECT) = lower(@p0)
     and EP.PROJ_VERSION = EV.VERS_VERSION
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetEntProjectInfoForEPName TO MSProjectServerRole
GO


/* Query #66003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetProjectCentralMenu
AS
select * from MSP_WEB_SECURITY_MENUS RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetProjectCentralMenu TO MSProjectServerRole
GO

/* Query #66004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetOrgMenu
AS
select O.WSEC_MENU_SEQ, 
       O.WSEC_MENU_LEVEL, 
       O.WSEC_MENU_ID, 
       M.WSEC_MENU_NAME 
  from MSP_WEB_SECURITY_ORG_MENU O, 
       MSP_WEB_SECURITY_MENUS M 
 where O.WSEC_MENU_SEQ <> 0 
   and O.WSEC_MENU_ID = M.WSEC_MENU_ID 
 order by WSEC_MENU_SEQ
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetOrgMenu TO MSProjectServerRole
GO

/* Query #66006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllFeaturesAndActions
AS
select * from MSP_WEB_SECURITY_FEATURES_ACTIONS RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllFeaturesAndActions TO MSProjectServerRole
GO

/* Query #66007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllGlobalActions
AS
--select * from MSP_WEB_SECURITY_FEATURES_ACTIONS where WSEC_IS_ACTION=1 and WSEC_ON_OBJECT=0 RETURN
select * 
  from MSP_WEB_SECURITY_FEATURES_ACTIONS 
 where WSEC_IS_ACTION = 1 
   and WSEC_ON_OBJECT = 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllGlobalActions TO MSProjectServerRole
GO



/* Query #66008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllCategoryActions
AS
--select * from MSP_WEB_SECURITY_FEATURES_ACTIONS where WSEC_IS_ACTION=1 and WSEC_ON_OBJECT=1 RETURN
select * 
  from MSP_WEB_SECURITY_FEATURES_ACTIONS 
 where WSEC_IS_ACTION = 1 
   and WSEC_ON_OBJECT = 1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllCategoryActions TO MSProjectServerRole
GO



/* Query #66009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllGroupsAUserIsIn
   @p0 UNIQUEIDENTIFIER
AS
--select GP.WSEC_GRP_GUID, GP.WSEC_GRP_NAME from MSP_WEB_SECURITY_GROUP_MEMBERS GM, MSP_WEB_SECURITY_GROUPS GP where GM.WRES_GUID=@p0 and GM.WSEC_GRP_GUID=GP.WSEC_GRP_GUID RETURN
select GP.WSEC_GRP_GUID, 
       GP.WSEC_GRP_NAME 
  from MSP_WEB_SECURITY_GROUP_MEMBERS GM, 
       MSP_WEB_SECURITY_GROUPS GP 
 where GM.WRES_GUID = @p0 
   and GM.WSEC_GRP_GUID = GP.WSEC_GRP_GUID
 order by GP.WSEC_GRP_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllGroupsAUserIsIn TO MSProjectServerRole
GO



/* Query #66010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllUsersInAGroup
   @p0 UNIQUEIDENTIFIER
AS
select RS.* 
  from MSP_WEB_SECURITY_GROUP_MEMBERS GM, 
       MSP_WEB_RESOURCES RS 
 where GM.WSEC_GRP_GUID = @p0 
   and GM.WRES_GUID = RS.WRES_GUID
   and RS.WRES_CAN_LOGIN=1
   and RS.WRES_COUNT_LICENSE=1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllUsersInAGroup TO MSProjectServerRole
GO



/* Query #66011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllActiveUsersOBName
AS
  select WRES_ID, WRES_GUID, RES_NAME 
    from MSP_WEB_RESOURCES 
   where WRES_IS_ENABLED = 1
     and WRES_CAN_LOGIN = 1
     and WRES_COUNT_LICENSE = 1
   order by RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllActiveUsersOBName TO MSProjectServerRole
GO


/* Query #66012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllUsersWOAdminOBName
AS
  select WRES_ID, WRES_GUID, RES_NAME 
    from MSP_WEB_RESOURCES 
   where WRES_IS_ENABLED = 1
     and WRES_CAN_LOGIN = 1
     and WRES_COUNT_LICENSE = 1
     and WRES_ID <> 1
   order by RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllUsersWOAdminOBName TO MSProjectServerRole
GO


/* Query #66013 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllUsersOBName
AS
  select WRES_ID, WRES_GUID, RES_NAME
    from MSP_WEB_RESOURCES 
   where WRES_CAN_LOGIN = 1
     and WRES_COUNT_LICENSE = 1
   order by RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllUsersOBName TO MSProjectServerRole
GO



/* Query #66014 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetOrgAllPermissions
  @p0   INT
AS
  select OP.*, CV.CONV_STRING as WSEC_FEA_ACT_NAME 
    from MSP_WEB_SECURITY_ORG_PERMISSIONS OP, 
         MSP_WEB_SECURITY_FEATURES_ACTIONS FA,
         MSP_WEB_CONVERSIONS CV
   where OP.WSEC_FEA_ACT_ID = FA.WSEC_FEA_ACT_ID
     and FA.WSEC_FEA_ACT_NAME_ID=CV.CONV_VALUE
     and CV.LANG_ID=@p0
   order by OP.WSEC_FEA_ACT_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetOrgAllPermissions TO MSProjectServerRole
GO



/* Query #66015 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetSPAllGlobalPermissions
   @p0 UNIQUEIDENTIFIER,
   @p1 INT
AS
  select SCP.WSEC_FEA_ACT_ID, 
         CV.CONV_STRING as WSEC_FEA_ACT_NAME,
         SCP.WSEC_ALLOW, 
         SCP.WSEC_DENY, 
         SCP.WSEC_ACCESS 
    from MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, 
         MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, 
         MSP_WEB_SECURITY_FEATURES_ACTIONS FA,
         MSP_WEB_CONVERSIONS CV
   where SCR.WSEC_SP_GUID = @p0 
     and SCR.WSEC_CAT_ID = 0 
     and SCR.WSEC_REL_ID = SCP.WSEC_REL_ID 
     and SCP.WSEC_FEA_ACT_ID = FA.WSEC_FEA_ACT_ID
     and FA.WSEC_FEA_ACT_NAME_ID=CV.CONV_VALUE
     and CV.LANG_ID=@p1
   order by SCP.WSEC_FEA_ACT_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetSPAllGlobalPermissions TO MSProjectServerRole
GO



/* Query #66016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetSPAllPermissionsOnCategory
   @p0 UNIQUEIDENTIFIER,
   @p1 INT,
   @p2 INT
AS
  select SCP.WSEC_FEA_ACT_ID, 
         CV.CONV_STRING as WSEC_FEA_ACT_NAME,
         SCP.WSEC_ALLOW, 
         SCP.WSEC_DENY, 
         SCP.WSEC_ACCESS 
    from MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, 
         MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, 
         MSP_WEB_SECURITY_FEATURES_ACTIONS FA,
         MSP_WEB_CONVERSIONS CV
   where SCR.WSEC_SP_GUID = @p0 
     and SCR.WSEC_CAT_ID = @p1 
     and SCR.WSEC_REL_ID = SCP.WSEC_REL_ID 
     and SCP.WSEC_FEA_ACT_ID = FA.WSEC_FEA_ACT_ID
     and FA.WSEC_FEA_ACT_NAME_ID=CV.CONV_VALUE
     and CV.LANG_ID=@p2
   order by SCP.WSEC_FEA_ACT_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetSPAllPermissionsOnCategory TO MSProjectServerRole
GO



/* Query #66019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllGroupMembers
   @p0 UNIQUEIDENTIFIER
AS
--select R.WRES_GUID, R.WRES_ID, R.RES_NAME from MSP_WEB_SECURITY_GROUP_MEMBERS M, MSP_WEB_RESOURCES R where M.WSEC_GRP_GUID=@p0 and M.WRES_GUID=R.WRES_GUID and M.WSEC_GRP_GUID <> M.WRES_GUID order by R.RES_NAME RETURN
select R.WRES_GUID, 
       R.WRES_ID, 
       R.RES_NAME 
  from MSP_WEB_SECURITY_GROUP_MEMBERS M, 
       MSP_WEB_RESOURCES R 
 where M.WSEC_GRP_GUID = @p0 
   and M.WRES_GUID = R.WRES_GUID 
   and M.WSEC_GRP_GUID <> M.WRES_GUID 
 order by R.RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllGroupMembers TO MSProjectServerRole
GO



/* Query #67000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllGroups
AS
select * 
  from MSP_WEB_SECURITY_GROUPS 
 order by WSEC_GRP_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllGroups TO MSProjectServerRole
GO



/* Query #67001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllCategories
AS
select * from MSP_WEB_SECURITY_CATEGORIES order by WSEC_CAT_NAME RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllCategories TO MSProjectServerRole
GO



/* Query #67002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllCatActIDs
  @p0 INT
AS
  select WSEC_FEA_ACT_ID, 
         CV.CONV_STRING as WSEC_FEA_ACT_NAME
    from MSP_WEB_SECURITY_FEATURES_ACTIONS FA,
         MSP_WEB_CONVERSIONS CV
   where WSEC_IS_ACTION <> 0
     and WSEC_ON_OBJECT <> 0
     and FA.WSEC_FEA_ACT_NAME_ID=CV.CONV_VALUE
     and CV.LANG_ID=@p0
   order by WSEC_FEA_ACT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllCatActIDs TO MSProjectServerRole
GO



/* Query #67003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllGlobalActIDs
  @p0 INT
AS
  select WSEC_FEA_ACT_ID, 
         CV.CONV_STRING as WSEC_FEA_ACT_NAME
    from MSP_WEB_SECURITY_FEATURES_ACTIONS FA,
         MSP_WEB_CONVERSIONS CV
   where WSEC_IS_ACTION <> 0 
     and WSEC_ON_OBJECT = 0
     and FA.WSEC_FEA_ACT_NAME_ID=CV.CONV_VALUE
     and CV.LANG_ID=@p0
   order by WSEC_FEA_ACT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllGlobalActIDs TO MSProjectServerRole
GO



/* Query #67004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResAllGroups
   @p0 UNIQUEIDENTIFIER
AS

select 
	GP.* 
from 
	MSP_WEB_SECURITY_GROUP_MEMBERS GM, 
	MSP_WEB_SECURITY_GROUPS GP 
where 
	GM.WRES_GUID=@p0 
	and GM.WSEC_GRP_GUID<>GM.WRES_GUID 
	and GM.WSEC_GRP_GUID=GP.WSEC_GRP_GUID 
order by GP.WSEC_GRP_NAME

RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResAllGroups TO MSProjectServerRole
GO



/* Query #67005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResAllCategories
   @p0 UNIQUEIDENTIFIER
AS
select SC.* 
  from MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, 
       MSP_WEB_SECURITY_CATEGORIES SC 
 where SCR.WSEC_SP_GUID = @p0 
   and SCR.WSEC_CAT_ID = SC.WSEC_CAT_ID
 order by SC.WSEC_CAT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResAllCategories TO MSProjectServerRole
GO



/* Query #67006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResInfo
   @p0 INT
AS
--select WRES_ID, WRES_GUID, RES_NAME, abs(WRES_USE_NT_LOGON) as ResourceAuthenNT, WRES_EMAIL, abs(WRES_IS_ENABLED) as ResourceIsActive , RES_PHONETICS from MSP_WEB_RESOURCES where WRES_ID=@p0 RETURN
select WRES_ID, 
       WRES_GUID, 
       RES_NAME, 
       abs(WRES_USE_NT_LOGON) as ResourceAuthenNT,
       WRES_NT_ACCOUNT, 
       WRES_EMAIL, 
       abs(WRES_IS_ENABLED) as ResourceIsActive, 
       RES_PHONETICS,
       WRES_CAN_LOGIN,
       WRES_COUNT_LICENSE,
       WRES_AD_GUID
  from MSP_WEB_RESOURCES 
 where WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResInfo TO MSProjectServerRole
GO



/* Query #67007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResAllGlobalPermissions
   @p0 UNIQUEIDENTIFIER
AS
--select SCP.WSEC_FEA_ACT_ID, SCP.WSEC_ALLOW, SCP.WSEC_DENY from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR where SCR.WSEC_SP_GUID=@p0 and SCR.WSEC_CAT_ID=0 and SCR.WSEC_REL_ID=SCP.WSEC_REL_ID RETURN
select SCP.WSEC_FEA_ACT_ID, 
       SCP.WSEC_ALLOW, 
       SCP.WSEC_DENY 
  from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, 
       MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR 
 where SCR.WSEC_SP_GUID = @p0 
   and SCR.WSEC_CAT_ID = 0 
   and SCR.WSEC_REL_ID = SCP.WSEC_REL_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResAllGlobalPermissions TO MSProjectServerRole
GO



/* Query #67008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResAllCatPermissions
   @p0 UNIQUEIDENTIFIER
AS
--select SCR.WSEC_CAT_ID, SCP.WSEC_FEA_ACT_ID, SCP.WSEC_ALLOW, SCP.WSEC_DENY from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, MSP_WEB_SECURITY_FEATURES_ACTIONS FA where SCR.WSEC_SP_GUID=@p0 and and SCR.WSEC_CAT_ID<>0 and SCR.WSEC_REL_ID=SCP.WSEC_REL_ID and SCP.WSEC_FEA_ACT_ID=FA.WSEC_FEA_ACT_ID RETURN
select SCR.WSEC_CAT_ID, 
       SCP.WSEC_FEA_ACT_ID, 
       SCP.WSEC_ALLOW, 
       SCP.WSEC_DENY 
  from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, 
       MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, 
       MSP_WEB_SECURITY_FEATURES_ACTIONS FA 
 where SCR.WSEC_SP_GUID = @p0 
   and SCR.WSEC_CAT_ID<>0
   and SCR.WSEC_REL_ID = SCP.WSEC_REL_ID 
   and SCP.WSEC_FEA_ACT_ID = FA.WSEC_FEA_ACT_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResAllCatPermissions TO MSProjectServerRole
GO



/* Query #67009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllActiveSPsWOAdminOBName
AS
  ( select WRES_ID           as WSEC_SP_ID,
           WRES_GUID         as WSEC_SP_GUID,
           RES_NAME          as WSEC_SP_NAME
      from MSP_WEB_RESOURCES 
     where WRES_CAN_LOGIN = 1 
       and WRES_COUNT_LICENSE = 1
       and WRES_ID <> 1
       and WRES_IS_ENABLED = 1
  )
  UNION 
  ( select - WSEC_GRP_ID     as WSEC_SP_ID,
           WSEC_GRP_GUID     as WSEC_SP_GUID,
           WSEC_GRP_NAME     as WSEC_SP_NAME
      from MSP_WEB_SECURITY_GROUPS
  )
  Order By WSEC_SP_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllActiveSPsWOAdminOBName TO MSProjectServerRole
GO



/* Query #67010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResCatPermByCatID
   @p0 INT
AS
-- Conversion to ANSI INNER JOIN
select V.WSEC_SP_ID,
       V.WSEC_SP_NAME, 
       WSEC_FEA_ACT_ID, 
       WSEC_ALLOW, 
       WSEC_DENY 
  from MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR 
       INNER JOIN MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP 
          ON SCR.WSEC_REL_ID = SCP.WSEC_REL_ID, 
       MSP_WEB_VW_SEC_ALLSP V 
 where SCR.WSEC_CAT_ID = @p0 
   and SCR.WSEC_SP_GUID = V.WSEC_SP_GUID 
 Order By WSEC_SP_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResCatPermByCatID TO MSProjectServerRole
GO



/* Query #67011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllResources
AS
--select WRES_ID, WRES_GUID, RES_NAME from MSP_WEB_RESOURCES order by RES_NAME RETURN
select WRES_ID, 
       WRES_GUID, 
       RES_NAME 
  from MSP_WEB_RESOURCES 
 order by RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllResources TO MSProjectServerRole
GO


/* Query #310031 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllCustomFieldsForAssnID
   @p0 INT,
   @p1 INT
AS
--Select * from MSP_WEB_WORKGROUP_FIELDS,MSP_WEB_ASSIGNMENTS,MSP_WEB_RESOURCES where MSP_WEB_WORKGROUP_FIELDS.WASSN_ID=@p0 and MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_WORKGROUP_FIELDS.WASSN_ID and MSP_WEB_RESOURCES.WRES_ID=WRES_ID_MGR and MSP_WEB_RESOURCES.RESERVED_DATA3=@p1 and MSP_WEB_RESOURCES.RESERVED_DATA4=@p2 order by MSP_WEB_WORKGROUP_FIELDS.FIELD_ID RETURN
-- Conversion to ANSI INNER JOIN
Select * 
  from MSP_WEB_WORKGROUP_FIELDS 
       INNER JOIN MSP_WEB_ASSIGNMENTS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_WORKGROUP_FIELDS.WASSN_ID
 where MSP_WEB_WORKGROUP_FIELDS.WASSN_ID = @p1
   and WRES_ID_MGR = @p0
 order by MSP_WEB_WORKGROUP_FIELDS.FIELD_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllCustomFieldsForAssnID TO MSProjectServerRole
GO


/* Query #310048 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetStatusRequestsForResIDNotSent
   @p0 INT
AS
--SELECT MSP_WEB_STATUS_REQUESTS.* FROM MSP_WEB_STATUS_REQUESTS, MSP_WEB_STATUS_REPORTS, MSP_WEB_RESOURCES Usr, MSP_WEB_RESOURCES Mgr WHERE WRES_ID_RECEIVER=@p0 and WREQ_IS_SENT<>0 and WREQ_IS_ENABLED<>0 and MSP_WEB_STATUS_REPORTS.WSR_ID=MSP_WEB_STATUS_REQUESTS.WSR_ID and Usr.WRES_ID=WRES_ID_RECEIVER and Usr.WRES_IS_ENABLED<>0 and Mgr.WRES_ID=MSP_WEB_STATUS_REPORTS.WRES_ID_MGR and Mgr.WRES_IS_ENABLED<>0 and Usr.RESERVED_DATA3=@p1 and Usr.RESERVED_DATA4=@p2 RETURN
-- Conversion to ANSI INNER JOIN
SELECT MSP_WEB_STATUS_REQUESTS.* 
  FROM MSP_WEB_STATUS_REQUESTS 
       INNER JOIN MSP_WEB_STATUS_REPORTS 
          ON MSP_WEB_STATUS_REPORTS.WSR_ID = MSP_WEB_STATUS_REQUESTS.WSR_ID, 
       MSP_WEB_RESOURCES Mgr 
 WHERE WRES_ID_RECEIVER = @p0 
   and WREQ_IS_SENT <> 0 
   and WREQ_IS_ENABLED <> 0 
   and Mgr.WRES_ID = MSP_WEB_STATUS_REPORTS.WRES_ID_MGR 
   and Mgr.WRES_IS_ENABLED <> 0 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetStatusRequestsForResIDNotSent TO MSProjectServerRole
GO


/* Query #310088 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetMatchingSRForSRID
   @p0 INT,
   @p1 INT
AS
--Select MSP_WEB_STATUS_RESPONSES.*,MSP_WEB_STATUS_REPORTS.WREPORT_NAME From MSP_WEB_STATUS_RESPONSES,MSP_WEB_STATUS_REPORTS,MSP_WEB_RESOURCES,MSP_WEB_STATUS_DISTRIBUTION Where MSP_WEB_STATUS_RESPONSES.WSR_ID=@p0 and MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_STATUS_REPORTS.WRES_ID_MGR and MSP_WEB_RESOURCES.RESERVED_DATA3=@p1 and MSP_WEB_RESOURCES.RESERVED_DATA4=@p2 and MSP_WEB_STATUS_REPORTS.WSR_ID=MSP_WEB_STATUS_RESPONSES.WSR_ID and WRESP_IS_MATCHING<>0 and MSP_WEB_STATUS_RESPONSES.WSUBMIT_STATUS=2 and MSP_WEB_STATUS_DISTRIBUTION.WRES_ID_DISTR_RECIP=MSP_WEB_STATUS_REPORTS.WRES_ID_MGR and MSP_WEB_STATUS_RESPONSES.WRESP_ID=MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID Order By MSP_WEB_STATUS_RESPONSES.WRES_ID,WSRESP_PERIOD_START,WUPDATE_STATUS RETURN
-- Conversion to ANSI INNER JOIN
Select MSP_WEB_STATUS_RESPONSES.*, 
       MSP_WEB_STATUS_REPORTS.WREPORT_NAME 
  From MSP_WEB_STATUS_REPORTS 
       INNER JOIN MSP_WEB_STATUS_RESPONSES 
          ON MSP_WEB_STATUS_REPORTS.WSR_ID = MSP_WEB_STATUS_RESPONSES.WSR_ID 
       INNER JOIN MSP_WEB_STATUS_DISTRIBUTION 
          ON MSP_WEB_STATUS_RESPONSES.WRESP_ID = MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID 
 Where MSP_WEB_STATUS_RESPONSES.WSR_ID = @p1
   and MSP_WEB_STATUS_REPORTS.WRES_ID_MGR = @p0
   and WRESP_IS_MATCHING <> 0 
   and MSP_WEB_STATUS_RESPONSES.WSUBMIT_STATUS = 2 
   and MSP_WEB_STATUS_DISTRIBUTION.WRES_ID_DISTR_RECIP = MSP_WEB_STATUS_REPORTS.WRES_ID_MGR 
 Order By MSP_WEB_STATUS_RESPONSES.WRES_ID, 
          WSRESP_PERIOD_START, 
          WUPDATE_STATUS
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetMatchingSRForSRID TO MSProjectServerRole
GO



/* Query #310090 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetRequestResources
   @p0 INT,
   @p1 INT
AS

Select MSP_WEB_RESOURCES.RES_NAME, 
       MSP_WEB_RESOURCES.WRES_ID 
  From MSP_WEB_RESOURCES 
       INNER JOIN MSP_WEB_STATUS_REQUESTS 
          ON MSP_WEB_STATUS_REQUESTS.WRES_ID_RECEIVER = MSP_WEB_RESOURCES.WRES_ID 
       INNER JOIN MSP_WEB_STATUS_REPORTS 
          ON MSP_WEB_STATUS_REQUESTS.WSR_ID = MSP_WEB_STATUS_REPORTS.WSR_ID
 Where MSP_WEB_STATUS_REQUESTS.WSR_ID = @p1 
   and MSP_WEB_STATUS_REQUESTS.WREQ_IS_SENT <> 0 
   and MSP_WEB_STATUS_REPORTS.WRES_ID_MGR = @p0
 Order By MSP_WEB_RESOURCES.WRES_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetRequestResources TO MSProjectServerRole
GO



/* Query #310226 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNewTasksForMsgId
   @p0 NVARCHAR(255)
AS
--Select WRES_ID From MSP_WEB_RESOURCES Where lower(RES_NAME)=lower(@p0) RETURN
Select WRES_ID 
  From MSP_WEB_RESOURCES 
 Where lower(RES_NAME) = lower(@p0)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNewTasksForMsgId TO MSProjectServerRole
GO



/* Query #310227 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResourceDelegateesLeadChange
AS
--Select WRES_ID,RES_NAME From MSP_WEB_RESOURCES Where WRES_IS_ENABLED<>0 Order By RES_NAME RETURN
Select WRES_ID, 
       RES_NAME 
  From MSP_WEB_RESOURCES 
 Where WRES_IS_ENABLED <> 0 
 Order By RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResourceDelegateesLeadChange TO MSProjectServerRole
GO



/* Query #310228 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResourceDelegateesNoLeadChange
   @p0 INT
AS
--Select WRES_ID,RES_NAME From MSP_WEB_RESOURCES Where WRES_ID<>@p0 and WRES_IS_ENABLED<>0 Order By RES_NAME RETURN
Select WRES_ID, 
       RES_NAME 
  From MSP_WEB_RESOURCES 
 Where WRES_ID <> @p0 
   and WRES_IS_ENABLED <> 0 
 Order By RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResourceDelegateesNoLeadChange TO MSProjectServerRole
GO


/* Query #310304 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetTasksAssignmentsForResIdwDelegation
   @p0 INT,
   @p1 DATETIME,
   @p2 INT
AS

select WOBJ_DOC_REF_CNT,
   WOBJ_ISSUE_REF_CNT,
   WOBJ_RISK_REF_CNT,
   ASSN_ACT_WORK,
   WA.WASSN_NOTE_STATUS,
   WA.RESERVED_DATA1 as TInsert,
   WASSN_CURRENT_TRACKING_MODE,
   WASSN_IS_NEW_ASSN,
   WASSN_DELETED_IN_PROJ,
   WR0.RES_NAME as TManagerName,
   WASSN_CREATED_BY_RES + WASSN_ASSIGNED_TO_EXISTING as TNewTaskIndic,
   abs(WDELEG_REJECT)+abs(WASSN_DELEG_PENDING - 1)+(CASE WHEN WR1.WRES_ID is null THEN 0 ELSE 1 END)+(case when WA.WRES_ID_TEAM_LEAD is null then -1 else 2 end) as TDelegIndicator,
   abs(WASSN_DELEG_PENDING) + abs(WASSN_DELETED_IN_PROJ) as TReadOnly,
   (CASE WHEN WA.WRES_ID <> @p0 THEN 1 ELSE 0 END) as TFlagIsCopy,
   WASSN_REQUEST_UPDATE,
   WASSN_RESOURCE_UPDATE,
   WASSN_ACTUALS_PENDING,
   WASSN_SEND_UPDATE_DATE,
   WA.WASSN_ID,
   TASK_UID_SUMMARY,
   TASK_UID,
   WASSN_UPDATE_STATUS,
   WA.WPROJ_ID,
   TASK_NAME,
   TASK_ID,
   ASSN_START_DATE,
   ASSN_FINISH_DATE,
   ASSN_WORK,
   ASSN_REM_WORK,
   WASSN_PCT_COMP,
   TASK_IS_SUMMARY,
   TASK_IS_MILESTONE,
   WASSN_MGR_UPDATED,
   WASSN_SEND_UPDATE_NEEDED,
   WA.WRES_ID,
   PROJ_NAME,
   WPROJ_IS_NONWORKING,
   WPROJ_DELEG_ALLOWED,
   WPROJ_TYPE,
   OPT_DEF_START_TIME,
   OPT_DEF_FINISH_TIME,
   WR.RES_NAME,
   WD.WRES_ID_DELEGATOR,
   WDELEG_DATE,
   WRES_ID_TEAM_LEAD,
   WNWRK_ENTRY_ID,
   WR1.RES_NAME AS TDelegatorName,
   WR2.RES_NAME AS TDelegeeName,
   WR3.RES_NAME AS TLeadName,
   WP.WPROJ_ADMINPROJECT 
FROM 
   (
      select WASSN_ID from MSP_WEB_ASSIGNMENTS WA where (WA.WRES_ID = @p0 and WA.WASSN_REMOVED_BY_RESOURCE = 0)
      UNION
      select WASSN_ID from MSP_WEB_ASSIGNMENTS WA (index = I_ASSIGN_WRESID_TEAM_LEAD) where WA.WRES_ID_TEAM_LEAD = @p0
      UNION
      select WASSN_ID from MSP_WEB_ASSIGNMENTS WA
                     where WA.WRES_ID <> @p0
                       and WA.TASK_IS_SUMMARY = 0
                       and WA.WASSN_ID in (
                              select WDA2.WASSN_ID 
                                from MSP_WEB_DELEGATIONS WD2
                                     inner join MSP_WEB_DELEGATION_ASSIGNMENTS WDA2 on WD2.WDELEG_ID = WDA2.WDELEG_ID
                               where WD2.WRES_ID_DELEGATOR = @p0 
                                 and WDA2.WDELEG_KEEP_COPY <> 0 
                                 and WD2.WDELEG_REJECT = 0
                           )
   ) as WT
   INNER JOIN MSP_WEB_ASSIGNMENTS WA ON WT.WASSN_ID = WA.WASSN_ID
   INNER JOIN MSP_WEB_PROJECTS WP ON WA.WPROJ_ID = WP.WPROJ_ID 
   INNER JOIN MSP_WEB_RESOURCES WR ON WA.WRES_ID = WR.WRES_ID 
   LEFT JOIN MSP_WEB_RESOURCES WR0 ON WA.WRES_ID_MGR = WR0.WRES_ID 
   LEFT JOIN MSP_WEB_RESOURCES WR3 ON WA.WRES_ID_TEAM_LEAD = WR3.WRES_ID 
   LEFT JOIN MSP_WEB_OBJECTS WO ON (WA.WPROJ_ID = WO.WOBJ_PROJ_ID AND WA.TASK_UID = WO.WOBJ_TASK_ID) 
   LEFT JOIN MSP_WEB_DELEGATIONS WD ON WA.WASSN_LAST_DELEG_ID = WD.WDELEG_ID 
   LEFT JOIN MSP_WEB_RESOURCES WR1 ON WD.WRES_ID_DELEGATOR = WR1.WRES_ID 
   LEFT JOIN MSP_WEB_RESOURCES WR2 ON WD.WRES_ID_DELEGATEE = WR2.WRES_ID 
WHERE WA.ASSN_BOOKING_TYPE = 0 and
      (WA.WASSN_IS_CONFIRMED<>0 or WP.WPROJ_ADMINPROJECT = 1)
      AND
      ( 
        ( 
          WA.TASK_IS_SUMMARY<>0 OR
          ( 
            (WA.ASSN_START_DATE < @p1) AND 
            (WA.WASSN_PCT_COMP< 100) 
          ) 
          OR 
          ( 
            (
              WA.ASSN_START_DATE IS NULL AND 
              (WA.ASSN_FINISH_DATE IS NULL OR WA.ASSN_FINISH_DATE< @p1)
            ) 
            AND 
            WA.WASSN_PCT_COMP< 100
          ) 
          OR 
          (WA.WASSN_SEND_UPDATE_NEEDED <> 0) OR 
          (WA.WASSN_PCT_COMP< 100 AND WASSN_PCT_COMP>0) OR 
          (WA.WASSN_IS_NEW_ASSN <> 0) OR 
          (@p2<>0)
        ) 
        OR 
        WP.WPROJ_ADMINPROJECT = 1
     )

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetTasksAssignmentsForResIdwDelegation TO MSProjectServerRole
GO




/* Query #10401 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNewTasksCheckRules
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT
AS
--Select distinct MSP_WEB_ASSIGNMENTS.WASSN_ID From MSP_WEB_ASSIGNMENTS,MSP_WEB_MESSAGES_ASSIGNMENTS,MSP_WEB_MESSAGES,MSP_WEB_RESOURCES MSP_WEB_RESOURCES,MSP_WEB_MGR_RULES, MSP_WEB_MGR_RULES_LISTS Where MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_IS_PROCESSED=0 and WASSN_IS_CONFIRMED<>0 and MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID and MSP_WEB_MESSAGES.WMSG_ID=@p0  AND MSP_WEB_MESSAGES_ASSIGNMENTS.WMSG_ID = MSP_WEB_MESSAGES.WMSG_ID and WMSG_PROJ_TYPE = 20 and TASK_IS_SUMMARY=0 and MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_ASSIGNMENTS.WRES_ID_MGR and MSP_WEB_RESOURCES.RESERVED_DATA3= @p2 and MSP_WEB_RESOURCES.RESERVED_DATA4=@p3 and MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID and MSP_WEB_MGR_RULES.WRES_ID_MGR=@p1 and (MSP_WEB_MGR_RULES.WRULE_TYPE = 20 or MSP_WEB_MGR_RULES.WRULE_TYPE=-1) and MSP_WEB_MGR_RULES.WRULE_CONDITION_TYPE = 0 and WRULE_IS_ENABLED<>0 AND ((MSP_WEB_ASSIGNMENTS.WPROJ_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID<>0) OR (MSP_WEB_ASSIGNMENTS.WPROJ_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID=0)) AND  ((MSP_WEB_ASSIGNMENTS.WRES_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID<>0) OR (MSP_WEB_ASSIGNMENTS.WRES_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=1 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID=0)) RETURN

Select distinct MSP_WEB_ASSIGNMENTS.WASSN_ID 
From MSP_WEB_ASSIGNMENTS,
     MSP_WEB_TRANSACTIONS,
     MSP_WEB_RESOURCES MSP_WEB_RESOURCES,
     MSP_WEB_MGR_RULES, 
     MSP_WEB_MGR_RULES_LISTS 
Where 
     MSP_WEB_TRANSACTIONS.WTRANS_STATE < 3 and
     MSP_WEB_TRANSACTIONS.WTRANS_TYPE = 2 and
     WASSN_IS_CONFIRMED<>0 and 
     MSP_WEB_TRANSACTIONS.WASSN_ID=MSP_WEB_ASSIGNMENTS.WASSN_ID and
     MSP_WEB_ASSIGNMENTS.WPROJ_ID = @p0 and
     MSP_WEB_ASSIGNMENTS.WRES_ID_MGR =@p1 AND
     TASK_IS_SUMMARY=0 and 
     MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_ASSIGNMENTS.WRES_ID_MGR and 
     MSP_WEB_RESOURCES.RESERVED_DATA3= @p2 and 
     MSP_WEB_RESOURCES.RESERVED_DATA4=@p3 and 
     MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID and 
     MSP_WEB_MGR_RULES.WRES_ID_MGR=@p1 and 
     (MSP_WEB_MGR_RULES.WRULE_TYPE = 20 or MSP_WEB_MGR_RULES.WRULE_TYPE=-1) and 
     MSP_WEB_MGR_RULES.WRULE_CONDITION_TYPE = 0 and 
     WRULE_IS_ENABLED<>0 AND 
      ((MSP_WEB_ASSIGNMENTS.WPROJ_ID Not In 
      (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
       FROM MSP_WEB_MGR_RULES_LISTS 
       WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND 
             MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
       MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID<>0) OR 
       (MSP_WEB_ASSIGNMENTS.WPROJ_ID In 
        (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
         FROM MSP_WEB_MGR_RULES_LISTS 
         WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND 
               MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
               MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID=0)) 
       AND  ((MSP_WEB_ASSIGNMENTS.WRES_ID Not In 
       (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
        FROM MSP_WEB_MGR_RULES_LISTS 
        WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND 
              MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
              MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID<>0) OR 
              (MSP_WEB_ASSIGNMENTS.WRES_ID In 
              (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
               FROM MSP_WEB_MGR_RULES_LISTS 
               WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=1 AND 
                     MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
                     MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID=0)) 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNewTasksCheckRules TO MSProjectServerRole
GO



/* Query #10402 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetStatusReqAssnsCheckRules
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT
AS
--Select distinct MSP_WEB_ASSIGNMENTS.WASSN_ID From MSP_WEB_ASSIGNMENTS,MSP_WEB_MESSAGES_ASSIGNMENTS,MSP_WEB_MESSAGES,MSP_WEB_RESOURCES MSP_WEB_RESOURCES,MSP_WEB_MGR_RULES, MSP_WEB_MGR_RULES_LISTS Where MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_IS_PROCESSED=0 and MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID and MSP_WEB_MESSAGES.WMSG_ID=@p0  AND MSP_WEB_MESSAGES_ASSIGNMENTS.WMSG_ID = MSP_WEB_MESSAGES.WMSG_ID and (WMSG_PROJ_TYPE = 5 or WMSG_PROJ_TYPE=39)  and TASK_IS_SUMMARY=0 and MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_ASSIGNMENTS.WRES_ID_MGR and MSP_WEB_RESOURCES.RESERVED_DATA3= @p2 and MSP_WEB_RESOURCES.RESERVED_DATA4=@p3 and MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID and MSP_WEB_MGR_RULES.WRES_ID_MGR=@p1 and (MSP_WEB_MGR_RULES.WRULE_TYPE = 40 or MSP_WEB_MGR_RULES.WRULE_TYPE=-1) and MSP_WEB_MGR_RULES.WRULE_CONDITION_TYPE = 0 AND WRULE_IS_ENABLED<>0 AND ((MSP_WEB_ASSIGNMENTS.WPROJ_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID<>0) OR (MSP_WEB_ASSIGNMENTS.WPROJ_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID=0)) AND  ((MSP_WEB_ASSIGNMENTS.WRES_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID<>0) OR (MSP_WEB_ASSIGNMENTS.WRES_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=1 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID=0)) RETURN
-- Conversion to ANSI INNER JOIN
Select distinct MSP_WEB_ASSIGNMENTS.WASSN_ID 
From MSP_WEB_ASSIGNMENTS,
     MSP_WEB_TRANSACTIONS,
     MSP_WEB_RESOURCES MSP_WEB_RESOURCES,
     MSP_WEB_MGR_RULES, 
     MSP_WEB_MGR_RULES_LISTS 
Where 
     MSP_WEB_TRANSACTIONS.WTRANS_STATE < 3 AND
     MSP_WEB_TRANSACTIONS.WTRANS_TYPE  < 3 AND
     MSP_WEB_TRANSACTIONS.WASSN_ID=MSP_WEB_ASSIGNMENTS.WASSN_ID and
     MSP_WEB_ASSIGNMENTS.WPROJ_ID = @p0 AND
     MSP_WEB_ASSIGNMENTS.WRES_ID_MGR = @p1 AND
     TASK_IS_SUMMARY=0 and 
     MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_ASSIGNMENTS.WRES_ID_MGR and 
     MSP_WEB_RESOURCES.RESERVED_DATA3= @p2 and 
     MSP_WEB_RESOURCES.RESERVED_DATA4=@p3 and 
     MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID and 
     MSP_WEB_MGR_RULES.WRES_ID_MGR=@p1 and 
     (MSP_WEB_MGR_RULES.WRULE_TYPE = 40 or MSP_WEB_MGR_RULES.WRULE_TYPE=-1) and 
     MSP_WEB_MGR_RULES.WRULE_CONDITION_TYPE = 0 AND WRULE_IS_ENABLED<>0 AND 
     ((MSP_WEB_ASSIGNMENTS.WPROJ_ID Not In 
     (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
     FROM MSP_WEB_MGR_RULES_LISTS 
     WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
     MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID<>0) OR 
     (MSP_WEB_ASSIGNMENTS.WPROJ_ID In 
     (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID 
      FROM MSP_WEB_MGR_RULES_LISTS 
     WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
     MSP_WEB_MGR_RULES.WRULE_IS_EXCL_PROJID=0)) AND
     ((MSP_WEB_ASSIGNMENTS.WRES_ID Not In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=0 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
     MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID<>0) OR (MSP_WEB_ASSIGNMENTS.WRES_ID In (SELECT MSP_WEB_MGR_RULES_LISTS.ITEM_ID FROM MSP_WEB_MGR_RULES_LISTS WHERE MSP_WEB_MGR_RULES_LISTS.ITEM_TYPE=1 AND MSP_WEB_MGR_RULES.WRULE_ID=MSP_WEB_MGR_RULES_LISTS.WRULE_ID) AND 
     MSP_WEB_MGR_RULES.WRULE_IS_EXCL_RES1ID=0)) 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetStatusReqAssnsCheckRules TO MSProjectServerRole
GO



/* Query #10403 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMgrsConditionRulesForStatusUpdt
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Select WRULE_ID, WRULE_CONDITION_TYPE, WRULE_FIELD1_ID, WRULE_FIELD2_ID,WRULE_OPERATOR,WRULE_OPERATOR,WRULE_VALTYPE,WRULE_INT_VAL,WRULE_DATE_VAL,WRULE_DECIMAL_VAL,WRULE_VARCHAR_VAL from MSP_WEB_MGR_RULES, MSP_WEB_RESOURCES WHERE WRULE_CONDITION_TYPE<>0 AND WRES_ID_MGR=@p0 AND WRULE_TYPE=40 AND WRULE_IS_ENABLED<>0 AND MSP_WEB_MGR_RULES.WRES_ID_MGR=MSP_WEB_RESOURCES.WRES_ID AND RESERVED_DATA3=@p1 AND RESERVED_DATA4=@p2 RETURN
Select WRULE_ID, 
       WRULE_CONDITION_TYPE, 
       WRULE_FIELD1_ID, 
       WRULE_FIELD2_ID, 
       WRULE_OPERATOR, 
       WRULE_OPERATOR, 
       WRULE_VALTYPE, 
       WRULE_INT_VAL, 
       WRULE_DATE_VAL, 
       WRULE_DECIMAL_VAL, 
       WRULE_VARCHAR_VAL 
  from MSP_WEB_MGR_RULES, 
       MSP_WEB_RESOURCES 
 WHERE WRULE_CONDITION_TYPE <> 0 
   AND WRES_ID_MGR = @p0 
   AND WRULE_TYPE = 40 
   AND WRULE_IS_ENABLED <> 0 
   AND MSP_WEB_MGR_RULES.WRES_ID_MGR = MSP_WEB_RESOURCES.WRES_ID 
   AND RESERVED_DATA3 = @p1 
   AND RESERVED_DATA4 = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMgrsConditionRulesForStatusUpdt TO MSProjectServerRole
GO



/* Query #10422 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetStatusReqAssns
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Select distinct MSP_WEB_ASSIGNMENTS.WASSN_ID From MSP_WEB_ASSIGNMENTS,MSP_WEB_MESSAGES,MSP_WEB_MESSAGES_ASSIGNMENTS,MSP_WEB_RESOURCES Where MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_MESSAGES_ASSIGNMENTS.WASSN_ID and MSP_WEB_MESSAGES.WMSG_ID=@p0 and MSP_WEB_MESSAGES.WMSG_ID=MSP_WEB_MESSAGES_ASSIGNMENTS.WMSG_ID AND TASK_IS_SUMMARY=0 and MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_ASSIGNMENTS.WRES_ID_MGR and MSP_WEB_RESOURCES.RESERVED_DATA3=@p1 and MSP_WEB_RESOURCES.RESERVED_DATA4=@p2 AND (MSP_WEB_MESSAGES.WMSG_PROJ_TYPE=5 or MSP_WEB_MESSAGES.WMSG_PROJ_TYPE= -1 or MSP_WEB_MESSAGES.WMSG_PROJ_TYPE=39) RETURN
Select distinct WA.WASSN_ID 
From MSP_WEB_ASSIGNMENTS WA 
        INNER JOIN MSP_WEB_TRANSACTIONS WT ON WA.WASSN_ID=WT.WASSN_ID 
        INNER JOIN MSP_WEB_RESOURCES WR ON WA.WRES_ID_MGR=WR.WRES_ID
Where 
     WT.WTRANS_STATE < 3 AND
     WT.WTRANS_TYPE  < 3 AND
     WA.WRES_ID_MGR =@p0 AND
     TASK_IS_SUMMARY=0 and 
     WR.RESERVED_DATA3=@p1 and 
     WR.RESERVED_DATA4=@p2 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetStatusReqAssns TO MSProjectServerRole
GO




/* Query #310500 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetNonPendingDelegationForProjUpdate
   @p0 INT,
   @p1 INT
AS
--Select WASSN_ID,TASK_NAME,ASSN_WORK,ASSN_REM_WORK,MSP_WEB_RESOURCES.RES_NAME,TASK_UID,ASSN_UID,WRES_ID_TEAM_LEAD,WLOCAL_PATH from ((MSP_WEB_ASSIGNMENTS INNER JOIN MSP_WEB_PROJECTS ON MSP_WEB_ASSIGNMENTS.WPROJ_ID=MSP_WEB_PROJECTS.WPROJ_ID) LEFT JOIN MSP_WEB_RESOURCES ON MSP_WEB_ASSIGNMENTS.WRES_ID=MSP_WEB_RESOURCES.WRES_ID) INNER JOIN MSP_WEB_RESOURCES WEB_RESOURCES2 ON MSP_WEB_ASSIGNMENTS.WRES_ID_MGR=WEB_RESOURCES2.WRES_ID where MSP_WEB_ASSIGNMENTS.WASSN_IS_DELEGATED<>0 and MSP_WEB_ASSIGNMENTS.WASSN_DELEG_PENDING=0 and MSP_WEB_ASSIGNMENTS.WASSN_DELETED_IN_PROJ=0 and MSP_WEB_ASSIGNMENTS.WPROJ_ID=@p0 and WEB_RESOURCES2.RESERVED_DATA3=@p1 and WEB_RESOURCES2.RESERVED_DATA4=@p2 Order by MSP_WEB_ASSIGNMENTS.WRES_ID RETURN
Select WASSN_ID, 
       TASK_NAME, 
       ASSN_WORK, 
       ASSN_REM_WORK, 
       MSP_WEB_RESOURCES.RES_NAME,
       MSP_WEB_RESOURCES.WRES_USE_NT_LOGON,
       MSP_WEB_RESOURCES.WRES_NT_ACCOUNT,
       TASK_UID, 
       ASSN_UID, 
       WRES_ID_TEAM_LEAD, 
       WLOCAL_PATH,
       WASSN_COMMENTS
  from ((MSP_WEB_ASSIGNMENTS 
       INNER JOIN MSP_WEB_PROJECTS 
          ON MSP_WEB_ASSIGNMENTS.WPROJ_ID = MSP_WEB_PROJECTS.WPROJ_ID) 
       LEFT JOIN MSP_WEB_RESOURCES 
         ON MSP_WEB_ASSIGNMENTS.WRES_ID = MSP_WEB_RESOURCES.WRES_ID) 
  where MSP_WEB_ASSIGNMENTS.WRES_ID_MGR = @p0
   and MSP_WEB_ASSIGNMENTS.WASSN_IS_DELEGATED <> 0 
   and MSP_WEB_ASSIGNMENTS.WASSN_DELEG_PENDING = 0 
   and MSP_WEB_ASSIGNMENTS.WASSN_DELETED_IN_PROJ = 0 
   and MSP_WEB_ASSIGNMENTS.WPROJ_ID = @p1 
 Order by MSP_WEB_ASSIGNMENTS.WRES_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetNonPendingDelegationForProjUpdate TO MSProjectServerRole
GO



/* Query #310502 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_UpdateDelegationFlagForFileID
   @p0 INT,
   @p1 INT
AS
--update MSP_WEB_ASSIGNMENTS set WASSN_IS_DELEGATED=0 where WASSN_IS_DELEGATED<>0 and WASSN_DELEG_PENDING=0 and WPROJ_ID=@p0 and WRES_ID_MGR in (select WRES_ID from MSP_WEB_RESOURCES where WRES_ID=@p1 and RESERVED_DATA3=@p2 AND RESERVED_DATA4=@p3) RETURN(0)
update MSP_WEB_ASSIGNMENTS 
   set WASSN_IS_DELEGATED = 0 
 where WASSN_IS_DELEGATED <> 0 
   and WASSN_DELEG_PENDING = 0 
   and WPROJ_ID = @p1 
   and WRES_ID_MGR = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_UpdateDelegationFlagForFileID TO MSProjectServerRole
GO



/* Query #310504 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_DeleteGhostAssignsAfterDelegUpdate
   @p0 INT,
   @p1 INT
AS
--delete from MSP_WEB_ASSIGNMENTS where WASSN_IS_DELEGATED<>0 and MSP_WEB_ASSIGNMENTS.WRES_ID=-1 and WASSN_DELEG_PENDING=0 and WPROJ_ID=@p0 and WRES_ID_MGR in (select WRES_ID from MSP_WEB_RESOURCES where WRES_ID=@p1 and RESERVED_DATA3=@p2 AND RESERVED_DATA4=@p3) RETURN(0)
delete 
  from MSP_WEB_ASSIGNMENTS 
 where WASSN_IS_DELEGATED <> 0 
   and MSP_WEB_ASSIGNMENTS.WRES_ID = -1 
   and WASSN_DELEG_PENDING = 0 
   and WPROJ_ID = @p1 
   and WRES_ID_MGR = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_DeleteGhostAssignsAfterDelegUpdate TO MSProjectServerRole
GO



/* Query #310510 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_SetResourceOffline
   @p0 INT
AS
update MSP_WEB_RESOURCES set WRES_IS_OFFLINE=1 where WRES_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_SetResourceOffline TO MSProjectServerRole
GO



/* Query #310511 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_SetResourceOnline
   @p0 INT
AS
update MSP_WEB_RESOURCES 
   set WRES_IS_OFFLINE = 0 
 where WRES_ID = @p0 
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_SetResourceOnline TO MSProjectServerRole
GO



/* Query #10700 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_getNonworkingAssnsFromNonworkingIDSorted
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT
AS
--select * from MSP_WEB_ASSIGNMENTS where WNWRK_ID = @p3 and WRES_ID=@p0 and WRES_ID in (select WRES_ID from MSP_WEB_RESOURCES where RESERVED_DATA3=@p1 AND RESERVED_DATA4=@p2) order by TASK_IS_SUMMARY RETURN
select * 
  from MSP_WEB_ASSIGNMENTS 
 where WNWRK_ID = @p3 
   and WRES_ID = @p0 
   and WRES_ID in (select WRES_ID 
                     from MSP_WEB_RESOURCES 
                    where RESERVED_DATA3 = @p1 
                      AND RESERVED_DATA4 = @p2) 
 order by TASK_IS_SUMMARY
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_getNonworkingAssnsFromNonworkingIDSorted TO MSProjectServerRole
GO



/* Query #310702 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_SetRulesEnable
   @p0 INT,
   @p1 INT,
   @p2 BIT
AS
--update MSP_WEB_MGR_RULES set WRULE_IS_ENABLED=@p2 where WRULE_ID=@p1 and WRES_ID_MGR=@p0 and WRES_ID_MGR in   (select WRES_ID from MSP_WEB_RESOURCES where RESERVED_DATA3=@p3 AND RESERVED_DATA4=@p4) RETURN(0)
update MSP_WEB_MGR_RULES 
   set WRULE_IS_ENABLED = @p2 
 where WRULE_ID = @p1 
   and WRES_ID_MGR = @p0 
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_SetRulesEnable TO MSProjectServerRole
GO



/* Query #110800 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_VerifyResIDForProjFileOpen
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--select WRES_ID from MSP_WEB_RESOURCES where WRES_ID=@p0 and RESERVED_DATA3=@p1 and RESERVED_DATA4=@p2 RETURN
select WRES_ID 
  from MSP_WEB_RESOURCES 
 where WRES_ID = @p0 
   and RESERVED_DATA3 = @p1 
   and RESERVED_DATA4 = @p2
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_VerifyResIDForProjFileOpen TO MSProjectServerRole
GO



/* Query #310801 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetProjPathForID
   @p0 INT
AS
--select WLOCAL_PATH from MSP_WEB_PROJECTS where WPROJ_ID=@p0 RETURN
select WLOCAL_PATH,WPROJ_TYPE 
  from MSP_WEB_PROJECTS 
 where WPROJ_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetProjPathForID TO MSProjectServerRole
GO



/* Query #310802 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetProjPathsForIDs
   @p0 INT,
   @p1 NTEXT
AS
select WLOCAL_PATH,WPROJ_TYPE
  from MSP_WEB_PROJECTS WP
       INNER JOIN dbo.MSP_WEB_FN_ConvertListToTable(@p1) LT ON WP.WPROJ_ID=LT.TokenVal
       INNER JOIN dbo.MSP_WEB_FN_SEC_GetAllProjectsResCanViewByViewID(@p0, 1013, -1, 3) PL ON WP.WPROJ_ID=PL.WPROJ_ID

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetProjPathsForIDs TO MSProjectServerRole
GO


/* Query #310803 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetLastSavedAdminTemplate
AS
select TOP 1 PROJ_PROJECT 
  from MSP_PROJECTS 
 where PROJ_ADMINPROJECT=1
   and PROJ_TYPE=1
 order by PROJ_CHECKOUTDATE DESC
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetLastSavedAdminTemplate TO MSProjectServerRole
GO


/* Query #311000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetAdminProjectAssignmentsForResID
   @p0 INT
AS
BEGIN
   select WASSN_ID,
          TASK_NAME,
          WA.WRES_ID,
          WA.WPROJ_ID,
          WP.PROJ_NAME, 
          TASK_UID,
          TASK_UID_SUMMARY,
          TASK_IS_SUMMARY,
          TASK_IS_MILESTONE,
          WASSN_CURRENT_TRACKING_MODE,
          WASSN_UPDATE_TRACKING_MODE,
          WASSN_NOTE_STATUS,
          WASSN_SEND_UPDATE_NEEDED,
          WASSN_UPDATE_STATUS
     from MSP_WEB_ASSIGNMENTS WA 
          INNER JOIN MSP_WEB_PROJECTS WP ON WA.WPROJ_ID=WP.WPROJ_ID 
    where WA.WRES_ID = @p0
      and WA.WASSN_DELETED_IN_PROJ = 0
      and WP.WPROJ_ADMINPROJECT = 1 
      and WP.WPROJ_IS_NONWORKING = 0
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetAdminProjectAssignmentsForResID TO MSProjectServerRole
GO

/* Query #335000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetTransactionsRecords
   @p0 INT,
   @p1 INT
AS
--Select WA.WASSN_NOTE_STATUS, (CASE WHEN WD.WDELEG_ID is not null THEN 6 END) as TDelegIndicator,WASSN_CREATED_BY_RES as TNewTaskIndic,WASSN_SEND_UPDATE_DATE,WR1.RES_NAME AS TDelegatorName,WR2.RES_NAME AS TDelegateeName,(CASE WHEN WTRANS_STATE=1 or WTRANS_STATE=2 THEN 1 ELSE 0 END) as TReadOnly,(CASE WHEN WTRANS_STATE=2 THEN 1 ELSE 0 END) as TTransUpdated,WD2.WDELEG_REJECT as TCurReject,WD.WDELEG_REJECT,WA.WASSN_ID,TASK_ID,TASK_NAME,ASSN_START_DATE,ASSN_FINISH_DATE,ASSN_WORK,ASSN_REM_WORK,WASSN_PCT_COMP,WRES_ID_MGR,WASSN_COMMENTS,WASSN_UPDATE_STATUS,WTRANS_ID,WTRANS_ACTION,WTRANS_TYPE,WTRANS_TYPE as TTransTypeName,WTRANS_DESC,WTRANS_DATE,WTRANS_PROJ_UPDATE_DATE,R1.WRES_ID,R1.RES_NAME,PROJ_NAME,WP.WPROJ_ID,R2.WRES_ID as TSenderID,R2.RES_NAME as TSenderName From ((((((((MSP_WEB_ASSIGNMENTS WA INNER JOIN MSP_WEB_TRANSACTIONS WT ON WA.WASSN_ID=WT.WASSN_ID) INNER JOIN MSP_WEB_PROJECTS WP ON WA.WPROJ_ID=WP.WPROJ_ID) INNER JOIN MSP_WEB_RESOURCES R1 ON WA.WRES_ID=R1.WRES_ID) INNER JOIN MSP_WEB_RESOURCES R2 ON WT.WRES_ID_TRANS_SENDER=R2.WRES_ID) LEFT JOIN MSP_WEB_DELEGATIONS WD ON WT.WDELEG_ID=WD.WDELEG_ID) LEFT JOIN MSP_WEB_DELEGATIONS WD2 ON WA.WASSN_LAST_DELEG_ID=WD2.WDELEG_ID) LEFT JOIN MSP_WEB_RESOURCES WR1 ON WD.WRES_ID_DELEGATOR=WR1.WRES_ID) LEFT JOIN MSP_WEB_RESOURCES WR2 ON WD.WRES_ID_DELEGATEE=WR2.WRES_ID) Where WTRANS_STATE<3 and WRES_ID_MGR=@p0 RETURN
declare @trans_query nvarchar(3000)

set @trans_query = N'Select WA.WASSN_NOTE_STATUS, 
       (CASE WHEN WD.WDELEG_ID is not null THEN 6 END) as TDelegIndicator, 
       WASSN_CREATED_BY_RES+WASSN_ASSIGNED_TO_EXISTING as TNewTaskIndic, 
       WASSN_SEND_UPDATE_DATE, 
       WR1.RES_NAME AS TDelegatorName, 
       WR2.RES_NAME AS TDelegateeName, 
       (CASE WHEN WTRANS_STATE = 1 
    or WTRANS_STATE = 2 THEN 1 
             ELSE 0 END) as TReadOnly, 
       (CASE WHEN WTRANS_STATE = 2 THEN 1 
             ELSE 0 END) as TTransUpdated, 
       WD2.WDELEG_REJECT as TCurReject, 
       WD.WDELEG_REJECT, 
       WA.WASSN_ID, 
       TASK_ID,
	   TASK_UID, 
       TASK_NAME, 
       ASSN_START_DATE, 
       ASSN_FINISH_DATE, 
       ASSN_WORK, 
       ASSN_ACT_WORK,
       ASSN_REM_WORK, 
       WASSN_PCT_COMP, 
       WASSN_CURRENT_TRACKING_MODE,
       WASSN_SEND_UPDATE_NEEDED,
       WRES_ID_MGR, 
       R3.RES_NAME as TManagerName, 
       WASSN_UPDATE_STATUS, 
       WTRANS_ID, 
       WTRANS_ACTION, 
       CASE WHEN WTRANS_ADJUST = 0 THEN (CASE WHEN WA.WASSN_ASSIGNED_TO_EXISTING=5 THEN 5 ELSE WTRANS_TYPE END) ELSE 4 END as WTRANS_TYPE, 
       CASE WHEN WTRANS_ADJUST = 0 THEN (CASE WHEN WA.WASSN_ASSIGNED_TO_EXISTING=5 THEN 5 ELSE WTRANS_TYPE END) ELSE 4 END as TTransTypeName, 
       WTRANS_DESC, 
       WTRANS_DATE, 
       WTRANS_PROJ_UPDATE_DATE, 
       R1.WRES_ID, 
       R1.RES_NAME, 
       PROJ_NAME, 
       WP.WPROJ_ID, 
       R2.WRES_ID as TSenderID, 
       R2.RES_NAME as TSenderName,
       WOBJ_DOC_REF_CNT,
       WOBJ_ISSUE_REF_CNT,
       WOBJ_RISK_REF_CNT
  From MSP_WEB_ASSIGNMENTS WA 
       INNER JOIN MSP_WEB_TRANSACTIONS WT ON WA.WASSN_ID = WT.WASSN_ID
       INNER JOIN MSP_WEB_PROJECTS WP ON WA.WPROJ_ID = WP.WPROJ_ID
       LEFT JOIN MSP_WEB_RESOURCES R1 ON WA.WRES_ID = R1.WRES_ID
       INNER JOIN MSP_WEB_RESOURCES R2 ON WT.WRES_ID_TRANS_SENDER = R2.WRES_ID
       INNER JOIN MSP_WEB_RESOURCES R3 ON WA.WRES_ID_MGR = R3.WRES_ID
       LEFT JOIN MSP_WEB_DELEGATIONS WD ON WT.WDELEG_ID = WD.WDELEG_ID
       LEFT JOIN MSP_WEB_DELEGATIONS WD2 ON WA.WASSN_LAST_DELEG_ID = WD2.WDELEG_ID
       LEFT JOIN MSP_WEB_RESOURCES WR1 ON WD.WRES_ID_DELEGATOR = WR1.WRES_ID
       LEFT JOIN MSP_WEB_RESOURCES WR2 ON WD.WRES_ID_DELEGATEE = WR2.WRES_ID
       LEFT JOIN MSP_WEB_OBJECTS WO ON (WA.WPROJ_ID=WO.WOBJ_PROJ_ID AND WA.TASK_UID=WO.WOBJ_TASK_ID)
 Where WTRANS_STATE < 3 
   and WRES_ID_MGR = ' + CAST(@p0 as nvarchar)

if (@p1 != -1)
   set @trans_query = @trans_query + N'and WP.WPROJ_ID=' + CAST(@p1 as nvarchar)

exec sp_executesql @trans_query

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetTransactionsRecords TO MSProjectServerRole
GO


/* Query #335004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetTransactionsHistoryRecords
   @p0 INT
AS
--Select (CASE WHEN WD.WDELEG_ID is not null THEN 6 END) as TDelegIndicator,WASSN_CREATED_BY_RES as TNewTaskIndic,WASSN_SEND_UPDATE_DATE,WR1.RES_NAME AS TDelegatorName,WR2.RES_NAME AS TDelegateeName,WD2.WDELEG_REJECT as TCurReject,WD.WDELEG_REJECT,WA.WASSN_ID,TASK_ID,TASK_NAME,ASSN_START_DATE,ASSN_FINISH_DATE,ASSN_WORK,ASSN_REM_WORK,WASSN_PCT_COMP,WRES_ID_MGR,WASSN_COMMENTS,WASSN_UPDATE_STATUS,WTRANS_ID,WTRANS_ACTION,WTRANS_TYPE,WTRANS_TYPE as TTransTypeName,WTRANS_DESC,WTRANS_DATE,WTRANS_PROJ_UPDATE_DATE,R1.WRES_ID,R1.RES_NAME,PROJ_NAME,WP.WPROJ_ID,R2.WRES_ID as TSenderID,R2.RES_NAME as TSenderName From ((((((((MSP_WEB_ASSIGNMENTS WA INNER JOIN MSP_WEB_TRANSACTIONS WT ON WA.WASSN_ID=WT.WASSN_ID) INNER JOIN MSP_WEB_PROJECTS WP ON WA.WPROJ_ID=WP.WPROJ_ID) INNER JOIN MSP_WEB_RESOURCES R1 ON WA.WRES_ID=R1.WRES_ID) INNER JOIN MSP_WEB_RESOURCES R2 ON WT.WRES_ID_TRANS_SENDER=R2.WRES_ID) LEFT JOIN MSP_WEB_DELEGATIONS WD ON WT.WDELEG_ID=WD.WDELEG_ID) LEFT JOIN MSP_WEB_DELEGATIONS WD2 ON WA.WASSN_LAST_DELEG_ID=WD2.WDELEG_ID) LEFT JOIN MSP_WEB_RESOURCES WR1 ON WD.WRES_ID_DELEGATOR=WR1.WRES_ID) LEFT JOIN MSP_WEB_RESOURCES WR2 ON WD.WRES_ID_DELEGATEE=WR2.WRES_ID) Where WTRANS_STATE=3 and WRES_ID_MGR=@p0 RETURN
Select (CASE WHEN WD.WDELEG_ID is not null THEN 6 END) as TDelegIndicator, 
       WASSN_CREATED_BY_RES+WASSN_ASSIGNED_TO_EXISTING as TNewTaskIndic, 
       WASSN_NOTE_STATUS,
       WASSN_SEND_UPDATE_DATE, 
       WR1.RES_NAME AS TDelegatorName, 
       WR2.RES_NAME AS TDelegateeName, 
       WD2.WDELEG_REJECT as TCurReject, 
       WD.WDELEG_REJECT, 
       WA.WASSN_ID, 
       TASK_ID,
       TASK_UID,
       TASK_NAME, 
       ASSN_START_DATE, 
       ASSN_FINISH_DATE, 
       ASSN_WORK, 
       ASSN_ACT_WORK,
       ASSN_REM_WORK, 
       WASSN_PCT_COMP, 
       WASSN_CURRENT_TRACKING_MODE,
       WRES_ID_MGR, 
       R3.RES_NAME as TManagerName,  
       WASSN_UPDATE_STATUS, 
       WTRANS_ID, 
       WTRANS_ACTION, 
       WTRANS_TYPE, 
       WTRANS_TYPE as TTransTypeName, 
       WTRANS_DESC, 
       WTRANS_DATE, 
       WTRANS_PROJ_UPDATE_DATE, 
       R1.WRES_ID, 
       R1.RES_NAME, 
       PROJ_NAME, 
       WP.WPROJ_ID, 
       R2.WRES_ID as TSenderID, 
       R2.RES_NAME as TSenderName,
       WOBJ_DOC_REF_CNT,
       WOBJ_ISSUE_REF_CNT,
       WOBJ_RISK_REF_CNT
  From MSP_WEB_ASSIGNMENTS WA INNER JOIN MSP_WEB_TRANSACTIONS WT ON WA.WASSN_ID = WT.WASSN_ID
       INNER JOIN MSP_WEB_PROJECTS WP ON WA.WPROJ_ID = WP.WPROJ_ID
       INNER JOIN MSP_WEB_RESOURCES R1 ON WA.WRES_ID = R1.WRES_ID
       INNER JOIN MSP_WEB_RESOURCES R2 ON WT.WRES_ID_TRANS_SENDER = R2.WRES_ID
       INNER JOIN MSP_WEB_RESOURCES R3 ON WA.WRES_ID_MGR = R3.WRES_ID
       LEFT JOIN MSP_WEB_DELEGATIONS WD ON WT.WDELEG_ID = WD.WDELEG_ID
       LEFT JOIN MSP_WEB_DELEGATIONS WD2 ON WA.WASSN_LAST_DELEG_ID = WD2.WDELEG_ID
       LEFT JOIN MSP_WEB_RESOURCES WR1 ON WD.WRES_ID_DELEGATOR = WR1.WRES_ID
       LEFT JOIN MSP_WEB_RESOURCES WR2 ON WD.WRES_ID_DELEGATEE = WR2.WRES_ID
       LEFT JOIN MSP_WEB_OBJECTS WO ON (WA.WPROJ_ID=WO.WOBJ_PROJ_ID AND WA.TASK_UID=WO.WOBJ_TASK_ID)
 Where WTRANS_STATE = 3 
   and WRES_ID_MGR = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetTransactionsHistoryRecords TO MSProjectServerRole
GO



/* Query #135010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetWeekStartOn
AS
Select WADMIN_WEEK_STARTS_ON from MSP_WEB_ADMIN RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetWeekStartOn TO MSProjectServerRole
GO



/* Query #200000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_AdminValidation
   @p0 INT,
   @p1 INT,
   @p2 INT
AS

SELECT 
	WRES_IS_ADMIN,
	WRES_GUID 
FROM 
	MSP_WEB_RESOURCES 
WHERE 
	WRES_ID=@p0 and 
	RESERVED_DATA3=@p1 and 
	RESERVED_DATA4=@p2 
	
RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_AdminValidation TO MSProjectServerRole
GO



/* Query #200200 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetAllViews
   @fEntMode INT
AS
--Select MSP_WEB_VIEW_REPORTS.*,WTABLE_NAME From MSP_WEB_VIEW_REPORTS LEFT JOIN MSP_WEB_VIEW_TABLES ON MSP_WEB_VIEW_REPORTS.WTABLE_ID=MSP_WEB_VIEW_TABLES.WTABLE_ID RETURN
if (@fEntMode = 0)
 begin
   Select MSP_WEB_VIEW_REPORTS.*, WTABLE_NAME 
     From MSP_WEB_VIEW_REPORTS LEFT JOIN MSP_WEB_VIEW_TABLES ON MSP_WEB_VIEW_REPORTS.WTABLE_ID = MSP_WEB_VIEW_TABLES.WTABLE_ID
    Where WVIEW_TYPE <= 2 or WVIEW_TYPE=5
 end
else
 begin
   Select MSP_WEB_VIEW_REPORTS.*, WTABLE_NAME 
    From MSP_WEB_VIEW_REPORTS LEFT JOIN MSP_WEB_VIEW_TABLES ON MSP_WEB_VIEW_REPORTS.WTABLE_ID = MSP_WEB_VIEW_TABLES.WTABLE_ID
 end

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetAllViews TO MSProjectServerRole
GO



/* Query #200201 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetFieldsForViewID
   @p0 INT,
   @p1 INT
AS
Select MSP_WEB_VIEW_FIELDS.WFIELD_ID, 
       CONV_STRING, 
       WVIEW_FIELD_ORDER 
  From MSP_WEB_VIEW_FIELDS 
       INNER JOIN MSP_WEB_VIEW_REPORTS_FIELDS 
          ON MSP_WEB_VIEW_FIELDS.WFIELD_ID = MSP_WEB_VIEW_REPORTS_FIELDS.WFIELD_ID 
       INNER JOIN MSP_WEB_CONVERSIONS 
          ON WFIELD_NAME_CONV_VALUE = CONV_VALUE
 Where LANG_ID = @p1 
   and MSP_WEB_VIEW_REPORTS_FIELDS.WVIEW_ID = @p0 
 Order By WVIEW_FIELD_ORDER
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetFieldsForViewID TO MSProjectServerRole
GO



/* Query #200205 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetAllResourcesForViews
AS
--Select WRES_ID,RES_NAME,WRES_INCL_TEAMASSIGN_RESOURCES From MSP_WEB_RESOURCES Where WRES_IS_ENABLED<>0 RETURN
Select WRES_ID, 
       RES_NAME, 
       WRES_INCL_TEAMASSIGN_RESOURCES 
  From MSP_WEB_RESOURCES 
 Where WRES_IS_ENABLED <> 0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetAllResourcesForViews TO MSProjectServerRole
GO



/* Query #200208 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetAllDSNsForViews
AS
--Select WDSN_ID,WDSN_NAME,WDSN_DESCRIPTION,WDSN_LOGIN_ID,(CASE WHEN WDSN_PASSWORD is not null THEN 1 ELSE 0 END) as TPasswordSet From MSP_WEB_VIEW_DSNS RETURN
Select WDSN_ID, 
       WDSN_NAME, 
       WDSN_DESCRIPTION, 
       WDSN_LOGIN_ID, 
       (CASE WHEN WDSN_PASSWORD is not null THEN 1 
             ELSE 0 END) as TPasswordSet 
  From MSP_WEB_VIEW_DSNS
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetAllDSNsForViews TO MSProjectServerRole
GO



/* Query #200209 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetCategoriesForViewID
   @p0 INT
AS
--Select C.WSEC_CAT_ID, C.WSEC_CAT_NAME From MSP_WEB_SECURITY_CATEGORIES C, MSP_WEB_SECURITY_CATEGORY_OBJECTS CO Where CO.WSEC_OBJ_TYPE=3 and CO.WSEC_OBJ_ID=^0 and CO.WSEC_CAT_ID=C.WSEC_CAT_ID Order by WSEC_CAT_NAME RETURN
Select C.WSEC_CAT_ID, C.WSEC_CAT_NAME 
  From MSP_WEB_SECURITY_CATEGORIES C, 
       MSP_WEB_SECURITY_CATEGORY_OBJECTS CO 
 Where CO.WSEC_OBJ_TYPE=3 
   and CO.WSEC_OBJ_ID=@p0 
   and CO.WSEC_CAT_ID=C.WSEC_CAT_ID 
 Order by WSEC_CAT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetCategoriesForViewID TO MSProjectServerRole
GO



/* Query #200211 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetGanttSchemeSettings
   @p0 DATETIME,
   @p1 DATETIME,
   @p2 INT
AS
Select MSP_WEB_GANTT_SETTINGS.*,@p0 as ASSN_START_DATE,@p1 as ASSN_FINISH_DATE,CONV_STRING,WGANTT_SCHEME_NAME 
from MSP_WEB_GANTT_SETTINGS
inner join MSP_WEB_GANTT_STYLES on MSP_WEB_GANTT_SETTINGS.WGANTT_STYLE_ID=MSP_WEB_GANTT_STYLES.WGANTT_STYLE_ID
inner join MSP_WEB_GANTT_SCHEMES on MSP_WEB_GANTT_SETTINGS.WGANTT_SCHEME_ID=MSP_WEB_GANTT_SCHEMES.WGANTT_SCHEME_ID
inner join MSP_WEB_CONVERSIONS on WGANTT_STYLE_CONV_VALUE=CONV_VALUE
Where LANG_ID=@p2
Order By MSP_WEB_GANTT_SETTINGS.WGANTT_STYLE_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetGanttSchemeSettings TO MSProjectServerRole
GO



/* Query #200212 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_ChangeWSO
   @p0 INT
AS
--Update MSP_WEB_ADMIN set WADMIN_WEEK_STARTS_ON=@p0 RETURN(0)
Update MSP_WEB_ADMIN 
   set WADMIN_WEEK_STARTS_ON = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_ChangeWSO TO MSProjectServerRole
GO



/* Query #200213 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetFieldsForViewIDSortByFieldName
   @p0 INT,
   @p1 INT
AS
Select MSP_WEB_VIEW_FIELDS.WFIELD_ID, 
       CONV_STRING, 
       WVIEW_FIELD_ORDER,
       WVIEW_FIELD_WIDTH,
       WVIEW_FIELD_AUTOSIZE
  From MSP_WEB_VIEW_FIELDS 
       INNER JOIN MSP_WEB_VIEW_REPORTS_FIELDS 
          ON MSP_WEB_VIEW_FIELDS.WFIELD_ID = MSP_WEB_VIEW_REPORTS_FIELDS.WFIELD_ID
       INNER JOIN MSP_WEB_CONVERSIONS 
	      ON WFIELD_NAME_CONV_VALUE = CONV_VALUE
 Where LANG_ID = @p1 
   and MSP_WEB_VIEW_REPORTS_FIELDS.WVIEW_ID = @p0 
 Order By CONV_STRING
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetFieldsForViewIDSortByFieldName TO MSProjectServerRole
GO



/* Query #210226 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_DeleteNonworkingAssnsForNonworkingId
   @p0 INT
AS
--delete from MSP_WEB_ASSIGNMENTS where WNWRK_ID = @p0 RETURN(0)
delete 
  from MSP_WEB_ASSIGNMENTS 
 where WNWRK_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_DeleteNonworkingAssnsForNonworkingId TO MSProjectServerRole
GO



/* Query #210227 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_RenameNonworkingSummaryAssnsForNonworkingId
   @p0 INT,
   @p1 NVARCHAR(255)
AS
--update MSP_WEB_ASSIGNMENTS set TASK_NAME=@p1 where WNWRK_ID=@p0 and TASK_IS_SUMMARY<>0 RETURN(0)
update MSP_WEB_ASSIGNMENTS 
   set TASK_NAME = @p1 
 where WNWRK_ID = @p0 
   and TASK_IS_SUMMARY <> 0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_RenameNonworkingSummaryAssnsForNonworkingId TO MSProjectServerRole
GO



/* Query #210228 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_RenameNonworkingAssnsForNonworkingId
   @p0 INT,
   @p1 NVARCHAR(255)
AS
--UPDATE MSP_WEB_ASSIGNMENTS SET TASK_NAME=@p1 WHERE WNWRK_ID=@p0 AND TASK_IS_SUMMARY=0 AND WNWRK_ENTRY_ID IS Null RETURN(0)
UPDATE MSP_WEB_ASSIGNMENTS 
   SET TASK_NAME = @p1 
 WHERE WNWRK_ID = @p0 
   AND TASK_IS_SUMMARY = 0 
   AND WNWRK_ENTRY_ID IS Null
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_RenameNonworkingAssnsForNonworkingId TO MSProjectServerRole
GO



/* Query #210229 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_RenameNonworkingCategoryForNonworkingId
   @p0 INT,
   @p1 NVARCHAR(255)
AS
--UPDATE MSP_WEB_NONWORKING_CATEGORIES SET WNWRK_NAME=@p1 WHERE WNWRK_ID=@p0 RETURN(0)
UPDATE MSP_WEB_NONWORKING_CATEGORIES 
   SET WNWRK_NAME = @p1 
 WHERE WNWRK_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_RenameNonworkingCategoryForNonworkingId TO MSProjectServerRole
GO



/* Query #210230 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_UpdateCodeForNonworkingId
   @p0 INT,
   @p1 NVARCHAR(255)
AS
--UPDATE MSP_WEB_NONWORKING_CATEGORIES SET WNWRK_CODE=@p1 WHERE WNWRK_ID=@p0 RETURN(0)
UPDATE MSP_WEB_NONWORKING_CATEGORIES 
   SET WNWRK_CODE = @p1 
 WHERE WNWRK_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_UpdateCodeForNonworkingId TO MSProjectServerRole
GO



/* Query #210231 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_UpdateOrderForNonworkingId
   @p0 INT,
   @p1 INT
AS
--UPDATE MSP_WEB_NONWORKING_CATEGORIES SET WNWRK_ORDER=@p1 WHERE WNWRK_ID=@p0 RETURN(0)
UPDATE MSP_WEB_NONWORKING_CATEGORIES 
   SET WNWRK_ORDER = @p1 
 WHERE WNWRK_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_UpdateOrderForNonworkingId TO MSProjectServerRole
GO



/* Query #210232 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_DeleteNonworkingForNonworkingId
   @p0 INT
AS
--DELETE FROM MSP_WEB_NONWORKING_CATEGORIES WHERE WNWRK_ID=@p0 RETURN(0)
DELETE 
  FROM MSP_WEB_NONWORKING_CATEGORIES 
 WHERE WNWRK_ID = @p0
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_DeleteNonworkingForNonworkingId TO MSProjectServerRole
GO



/* Query #210233 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_DeleteAllLinksAndContents
AS
delete from MSP_WEB_ADMIN_LINKS RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_DeleteAllLinksAndContents TO MSProjectServerRole
GO



/* Query #210236 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_DeleteNonworkingWorkForNonworkingId
   @p0 INT
AS
--delete from MSP_WEB_WORK where WASSN_ID in (select WASSN_ID from MSP_WEB_ASSIGNMENTS where WNWRK_ID=@p0) RETURN(0)
delete 
  from MSP_WEB_WORK 
 where WASSN_ID in (select WASSN_ID 
                      from MSP_WEB_ASSIGNMENTS 
                     where WNWRK_ID = @p0)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_DeleteNonworkingWorkForNonworkingId TO MSProjectServerRole
GO



/* Query #220000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetAllUsersOBName
AS
--SELECT WRES_ID, RES_NAME, abs(WRES_USE_NT_LOGON) as ResourceAuthenNT, WRES_EMAIL, 2*abs(WRES_IS_ADMIN)+abs(abs(WRES_IS_ADMIN)-1)*abs(WRES_IS_MANAGER) as ResourceRole, abs(WRES_IS_ENABLED) as ResourceIsActive , RES_PHONETICS FROM MSP_WEB_RESOURCES order by RES_NAME RETURN
SELECT WRES_ID, 
       RES_NAME,
	   WRES_NT_ACCOUNT,
       abs(WRES_USE_NT_LOGON) as ResourceAuthenNT, 
       WRES_EMAIL, 
       abs(WRES_IS_ENABLED) as ResourceIsActive, 
       RES_PHONETICS,
       WRES_LAST_CONNECT
  FROM MSP_WEB_RESOURCES 
 WHERE WRES_CAN_LOGIN = 1
   and WRES_COUNT_LICENSE = 1
 ORDER BY RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetAllUsersOBName TO MSProjectServerRole
GO



/* Query #265000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetResourceGroups
   @p0 INT
AS
--select WSEC_GRP_NAME from MSP_WEB_SECURITY_GROUP_MEMBERS GM, MSP_WEB_SECURITY_GROUPS GP, MSP_WEB_RESOURCES RS where RS.WRES_ID=@p0 and RS.WRES_GUID=GM.WRES_GUID and GM.WSEC_GRP_GUID=GP.WSEC_GRP_GUID RETURN
-- Conversion to ANSI INNER JOIN
select WSEC_GRP_NAME 
  from MSP_WEB_SECURITY_GROUP_MEMBERS GM 
       INNER JOIN MSP_WEB_SECURITY_GROUPS GP 
          ON GM.WSEC_GRP_GUID = GP.WSEC_GRP_GUID 
       INNER JOIN MSP_WEB_RESOURCES RS 
          ON RS.WRES_GUID = GM.WRES_GUID 
 where RS.WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetResourceGroups TO MSProjectServerRole
GO



/* Query #265001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetResourceALLCategories
   @p0 INT
AS
select distinct SC.WSEC_CAT_NAME 
  from MSP_WEB_RESOURCES RS 
       INNER JOIN MSP_WEB_SECURITY_SP_CAT_RELATIONS SR 
          ON RS.WRES_GUID = SR.WSEC_SP_GUID
       INNER JOIN MSP_WEB_SECURITY_CATEGORIES SC 
          ON SR.WSEC_CAT_ID = SC.WSEC_CAT_ID 
 where RS.WRES_ID = @p0
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetResourceALLCategories TO MSProjectServerRole
GO



/* Query #265002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetAllCategories
AS
--select * from MSP_WEB_SECURITY_CATEGORIES order by WSEC_CAT_NAME RETURN
select * 
  from MSP_WEB_SECURITY_CATEGORIES 
 order by WSEC_CAT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetAllCategories TO MSProjectServerRole
GO



/* Query #265003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetProjectsForCategoryID
   @p0 INT
AS
--select P.WPROJ_ID, P.PROJ_NAME from MSP_WEB_PROJECTS P, MSP_WEB_SECURITY_CATEGORY_OBJECTS O Where O.WSEC_OBJ_TYPE=1 and O.WSEC_OBJ_ID=P.WPROJ_ID and O.WSEC_CAT_ID=@p0 Order By PROJ_NAME RETURN
-- Conversion to ANSI INNER JOIN
select P.WPROJ_ID, 
       P.PROJ_NAME 
  from MSP_WEB_PROJECTS P 
       INNER JOIN MSP_WEB_SECURITY_CATEGORY_OBJECTS O 
          ON O.WSEC_OBJ_ID = P.WPROJ_ID 
 Where O.WSEC_OBJ_TYPE = 1 
   and O.WSEC_CAT_ID = @p0 
 Order By PROJ_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetProjectsForCategoryID TO MSProjectServerRole
GO



/* Query #265004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetProjRulesForCategoryID
   @p0 INT
AS
--select WSEC_OBJ_RULE_TYPE from MSP_WEB_SECURITY_CATEGORY_RULES where WSEC_CAT_ID=@p0 and wsec_obj_type=1 RETURN
select WSEC_OBJ_RULE_TYPE 
  from MSP_WEB_SECURITY_CATEGORY_RULES 
 where WSEC_CAT_ID = @p0 
   and WSEC_OBJ_TYPE = 1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetProjRulesForCategoryID TO MSProjectServerRole
GO



/* Query #265005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetViewsForCategoryID
   @p0 INT
AS
--select V.WVIEW_ID,WVIEW_NAME,WVIEW_TYPE,WVIEW_REPORT_KIND from MSP_WEB_VIEW_REPORTS V, MSP_WEB_SECURITY_CATEGORY_OBJECTS SCO where SCO.WSEC_CAT_ID=@p0 and SCO.WSEC_OBJ_TYPE=3 and SCO.WSEC_OBJ_ID=V.WVIEW_ID Order By WVIEW_NAME RETURN
-- Conversion to ANSI INNER JOIN
select V.WVIEW_ID, 
       WVIEW_NAME, 
       WVIEW_TYPE, 
       WVIEW_REPORT_KIND 
  from MSP_WEB_VIEW_REPORTS V 
       INNER JOIN MSP_WEB_SECURITY_CATEGORY_OBJECTS SCO 
          ON SCO.WSEC_OBJ_ID = V.WVIEW_ID 
 where SCO.WSEC_CAT_ID = @p0 
   and SCO.WSEC_OBJ_TYPE = 3 
 Order By WVIEW_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetViewsForCategoryID TO MSProjectServerRole
GO



/* Query #265006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetUsersForCategoryID
   @p0 INT
AS
--select V.WSEC_SP_GUID, V.WSEC_SP_NAME from MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, MSP_WEB_VW_SEC_ALLSP V where WSEC_CAT_ID=@p0 and SCR.WSEC_SP_GUID=V.WSEC_SP_GUID RETURN
select V.WSEC_SP_GUID, 
       V.WSEC_SP_NAME 
  from MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, 
       MSP_WEB_VW_SEC_ALLSP V 
 where WSEC_CAT_ID = @p0 
   and SCR.WSEC_SP_GUID = V.WSEC_SP_GUID
 order by V.WSEC_SP_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetUsersForCategoryID TO MSProjectServerRole
GO



/* Query #265007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetResAssignmentsForCategoryID
   @p0 INT
AS
--select WRES_ID, RES_NAME from MSP_WEB_SECURITY_CATEGORY_OBJECTS, MSP_WEB_RESOURCES where WSEC_CAT_ID=@p0 and WSEC_OBJ_TYPE=2 and WSEC_OBJ_ID=WRES_ID RETURN
select WRES_ID, 
       RES_NAME 
  from MSP_WEB_SECURITY_CATEGORY_OBJECTS, 
       MSP_WEB_RESOURCES 
 where WSEC_CAT_ID = @p0 
   and WSEC_OBJ_TYPE = 2 
   and WSEC_OBJ_ID = WRES_ID
 Order By RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetResAssignmentsForCategoryID TO MSProjectServerRole
GO


/* Query #310021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_SR_GetSRsForPeriod
   @p0 INT,
   @p1 DATETIME
AS
--SELECT MSP_WEB_STATUS_RESPONSES.*,MSP_WEB_STATUS_REPORTS.WREPORT_NAME,WSUBMIT_STATUS, CASE WHEN (WSUBMIT_STATUS=2) or (WUPDATE_STATUS>-1) or (WREPORT_UNREQUESTED<>0) THEN 1 ELSE 0 END as Submitted, CASE WHEN (WSUBMIT_STATUS=1) THEN 1 ELSE 0 END as Saved, CASE WHEN (WUPDATE_STATUS>-1) THEN 1 ELSE 0 END as Updated, CASE WHEN (WSUBMIT_STATUS<2) and (WSRESP_PERIOD_FINISH<@p1) and (WUPDATE_STATUS=-1) and (WREPORT_UNREQUESTED=0) THEN 1 ELSE 0 END as Late From MSP_WEB_STATUS_RESPONSES,MSP_WEB_STATUS_REPORTS,MSP_WEB_STATUS_DISTRIBUTION Where MSP_WEB_STATUS_REPORTS.WSR_ID = MSP_WEB_STATUS_RESPONSES.WSR_ID and (WUPDATE_STATUS=-1 or WUPDATE_STATUS = MSP_WEB_STATUS_RESPONSES.WRESP_ID or (WSUBMIT_STATUS<2 and WUPDATE_STATUS<>MSP_WEB_STATUS_RESPONSES.WRESP_ID)) and MSP_WEB_STATUS_DISTRIBUTION.WRES_ID_DISTR_RECIP=@p0 and MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID = MSP_WEB_STATUS_RESPONSES.WRESP_ID and MSP_WEB_STATUS_DISTRIBUTION.WRES_ID_DISTR_RECIP=MSP_WEB_STATUS_RESPONSES.WRES_ID Order by WSUBMIT_DATE RETURN
-- Conversion to ANSI INNER JOIN
SELECT MSP_WEB_STATUS_RESPONSES.*, 
       MSP_WEB_STATUS_REPORTS.WREPORT_NAME, 
       WSUBMIT_STATUS, 
       CASE WHEN (WSUBMIT_STATUS = 2) 
    or (WUPDATE_STATUS > -1) 
    or (WREPORT_UNREQUESTED <> 0) THEN 1 
            ELSE 0 END as Submitted, 
       CASE WHEN (WSUBMIT_STATUS = 1) THEN 1 
            ELSE 0 END as Saved, 
       CASE WHEN (WUPDATE_STATUS > -1) THEN 1 
            ELSE 0 END as Updated, 
       CASE WHEN (WSUBMIT_STATUS < 2) 
   and (WSRESP_PERIOD_FINISH < @p1) 
   and (WUPDATE_STATUS = -1) 
   and (WREPORT_UNREQUESTED = 0) THEN 1 
            ELSE 0 END as Late 
  From MSP_WEB_STATUS_RESPONSES 
       INNER JOIN MSP_WEB_STATUS_REPORTS 
          ON MSP_WEB_STATUS_REPORTS.WSR_ID = MSP_WEB_STATUS_RESPONSES.WSR_ID 
       INNER JOIN MSP_WEB_STATUS_DISTRIBUTION 
          ON MSP_WEB_STATUS_DISTRIBUTION.WRESP_ID = MSP_WEB_STATUS_RESPONSES.WRESP_ID 
 Where (WUPDATE_STATUS = -1 
            or WUPDATE_STATUS = MSP_WEB_STATUS_RESPONSES.WRESP_ID 
            or (WSUBMIT_STATUS < 2 
                   and WUPDATE_STATUS <> MSP_WEB_STATUS_RESPONSES.WRESP_ID)) 
   and MSP_WEB_STATUS_DISTRIBUTION.WRES_ID_DISTR_RECIP = @p0 
   and MSP_WEB_STATUS_DISTRIBUTION.WRES_ID_DISTR_RECIP = MSP_WEB_STATUS_RESPONSES.WRES_ID 
 Order by WSUBMIT_DATE
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_SR_GetSRsForPeriod TO MSProjectServerRole
GO



/* Query #335100 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetActuals
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Select WWORK_TYPE,WWORK_START,WWORK_FINISH,WWORK_VALUE From MSP_WEB_WORK,MSP_WEB_ASSIGNMENTS Where MSP_WEB_WORK.WASSN_ID=@p0 and MSP_WEB_ASSIGNMENTS.WRES_ID_MGR=@p1 and MSP_WEB_WORK.WASSN_ID=MSP_WEB_ASSIGNMENTS.WASSN_ID RETURN
Select WWORK_TYPE, 
       WWORK_START, 
       WWORK_FINISH, 
       WWORK_VALUE 
  From MSP_WEB_WORK, 
       MSP_WEB_ASSIGNMENTS 
 Where MSP_WEB_WORK.WASSN_ID = @p0 
   and MSP_WEB_ASSIGNMENTS.WRES_ID_MGR = @p1 
   and (@p2=1 or WWORK_TYPE > 0)
   and MSP_WEB_WORK.WASSN_ID = MSP_WEB_ASSIGNMENTS.WASSN_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetActuals TO MSProjectServerRole
GO


/* Query #335102 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetNewTasks
   @p0 INT,
   @p1 INT
AS
--Select WLOCAL_PATH,RES_NAME,TASK_NAME,ASSN_UID,ASSN_START_DATE,ASSN_FINISH_DATE,ASSN_WORK,ASSN_REM_WORK,WASSN_COMMENTS,TASK_UID_SUMMARY,TASK_UID,MSP_WEB_ASSIGNMENTS.WASSN_ID,WASSN_PARENT_ID From MSP_WEB_PROJECTS,MSP_WEB_RESOURCES,MSP_WEB_ASSIGNMENTS,MSP_WEB_TRANSACTIONS Where WASSN_CREATED_BY_RES=2 and MSP_WEB_PROJECTS.WPROJ_ID=@p0 and MSP_WEB_ASSIGNMENTS.WPROJ_ID=MSP_WEB_PROJECTS.WPROJ_ID and MSP_WEB_ASSIGNMENTS.WRES_ID=MSP_WEB_RESOURCES.WRES_ID and WRES_ID_MGR=@p1 and MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_TRANSACTIONS.WASSN_ID and WTRANS_TYPE=2 and WTRANS_STATE<3 and WTRANS_ACTION=1 RETURN
-- Conversion to ANSI INNER JOIN
Select WLOCAL_PATH, 
       RES_NAME,
       WRES_USE_NT_LOGON,
       WRES_NT_ACCOUNT, 
       TASK_NAME, 
       ASSN_UID, 
       ASSN_START_DATE, 
       ASSN_FINISH_DATE, 
       ASSN_WORK, 
       ASSN_REM_WORK, 
       WASSN_COMMENTS, 
       TASK_UID_SUMMARY, 
       TASK_UID, 
       WASSN_PCT_COMP,
       WASSN_CURRENT_TRACKING_MODE,
       WASSN_UPDATE_TRACKING_MODE,
       MSP_WEB_ASSIGNMENTS.WASSN_ID, 
       WASSN_PARENT_ID 
  From MSP_WEB_PROJECTS 
       INNER JOIN MSP_WEB_ASSIGNMENTS 
          ON MSP_WEB_ASSIGNMENTS.WPROJ_ID = MSP_WEB_PROJECTS.WPROJ_ID 
       INNER JOIN MSP_WEB_RESOURCES 
          ON MSP_WEB_ASSIGNMENTS.WRES_ID = MSP_WEB_RESOURCES.WRES_ID 
       INNER JOIN MSP_WEB_TRANSACTIONS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID 
 Where WASSN_CREATED_BY_RES = 2 
   and MSP_WEB_PROJECTS.WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1 
   and WTRANS_TYPE = 2 
   and WTRANS_STATE < 3 
   and WTRANS_ACTION = 1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetNewTasks TO MSProjectServerRole
GO


/* Query #335104 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetAllTransProjects
   @p0 INT,
   @p1 INT
AS
declare @trans_query nvarchar(1000)

set @trans_query = N'SELECT WPROJ_ID,WPROJ_TYPE,PROJ_NAME,WPROJ_ADMINPROJECT 
                     FROM MSP_WEB_PROJECTS
                     WHERE WPROJ_ID in ( 
                        SELECT DISTINCT WPROJ_ID 
                        FROM MSP_WEB_ASSIGNMENTS 
                             INNER JOIN MSP_WEB_TRANSACTIONS 
                                ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID 
                        WHERE WRES_ID_MGR = ' + CAST(@p0 as nvarchar) + 
                            ' and WTRANS_ACTION > 0 
                              and WTRANS_STATE < 3)'

if (@p1 != -1)
   set @trans_query = @trans_query + N'and WPROJ_ID=' + CAST(@p1 as nvarchar)

exec sp_executesql @trans_query

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetAllTransProjects TO MSProjectServerRole
GO



/* Query #335105 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_SetTransStateToUpdated
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT,
   @p4 DATETIME
AS
--UPDATE MSP_WEB_TRANSACTIONS SET WTRANS_STATE=@p3,WTRANS_PROJ_UPDATE_DATE=@p4 WHERE WTRANS_STATE<2 and WTRANS_ACTION>0 and WTRANS_TYPE=@p2 and WASSN_ID in (SELECT WASSN_ID FROM MSP_WEB_ASSIGNMENTS WHERE WRES_ID_MGR=@p0 and WPROJ_ID=@p1) RETURN(0)
UPDATE MSP_WEB_TRANSACTIONS 
   SET WTRANS_STATE = @p3, 
       WTRANS_PROJ_UPDATE_DATE = @p4 
 WHERE WTRANS_STATE < 2 
   and WTRANS_ACTION > 0 
   and WTRANS_TYPE = @p2 
   and WASSN_ID in (SELECT WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS 
                     WHERE WRES_ID_MGR = @p0 
                       and WPROJ_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_SetTransStateToUpdated TO MSProjectServerRole
GO

/* Query #335106 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetTasksUpdatesForRes
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT
AS
--Select WA.WASSN_ID,ASSN_UID,WRES_ID,TASK_NAME,WASSN_PCT_COMP,WASSN_CURRENT_TRACKING_MODE,WASSN_UPDATE_TRACKING_MODE,ASSN_START_DATE,ASSN_FINISH_DATE,ASSN_WORK,ASSN_REM_WORK,WASSN_COMMENTS,WASSN_IS_CONFIRMED,WASSN_DELETED_IN_PROJ,WASSN_SEND_UPDATE_NEEDED From MSP_WEB_ASSIGNMENTS WA,MSP_WEB_TRANSACTIONS WT Where WA.WASSN_ID=WT.WASSN_ID and WPROJ_ID=@p0 and WRES_ID_MGR=@p1 and WRES_ID=@p2 and TASK_IS_SUMMARY=0 and WTRANS_STATE<3 and WTRANS_TYPE<2 and WTRANS_ACTION=1 RETURN
-- Conversion to ANSI INNER JOIN
Select WA.WASSN_ID, 
       ASSN_UID, 
       WRES_ID, 
       TASK_NAME, 
       WASSN_PCT_COMP, 
       WASSN_CURRENT_TRACKING_MODE, 
       WASSN_UPDATE_TRACKING_MODE, 
       ASSN_START_DATE, 
       ASSN_FINISH_DATE, 
       ASSN_WORK, 
       ASSN_REM_WORK, 
       WASSN_COMMENTS, 
       WASSN_IS_CONFIRMED, 
       WASSN_DELETED_IN_PROJ, 
       WASSN_SEND_UPDATE_NEEDED 
  From MSP_WEB_ASSIGNMENTS WA 
       INNER JOIN MSP_WEB_TRANSACTIONS WT 
          ON WA.WASSN_ID = WT.WASSN_ID 
 Where WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1 
   and WRES_ID = @p2 
   and TASK_IS_SUMMARY = 0 
   and WTRANS_STATE < 3 
   and (WTRANS_TYPE < 1 - @p3 or WTRANS_TYPE = @p3) 
   and WTRANS_ACTION = 1
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetTasksUpdatesForRes TO MSProjectServerRole
GO



/* Query #335107 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetAllCustomFieldsForTaskUpdates
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Select distinct WWF.FIELD_ID,CUSTFIELD_TYPE,WWORKGRP_INFO_IS_READONLY from MSP_WEB_WORKGROUP_FIELDS WWF,MSP_WEB_WORKGROUP_FIELDS_INFO WWFI,MSP_WEB_PROJECT_WORKGROUP_INFO WPWI,MSP_WEB_ASSIGNMENTS WA,MSP_WEB_TRANSACTIONS WT where WWF.FIELD_ID=WWFI.FIELD_ID and WWFI.CUSTFIELD_INFO_ID=WPWI.CUSTFIELD_INFO_ID and WPWI.WPROJ_ID=WA.WPROJ_ID and WA.WASSN_ID=WT.WASSN_ID and WA.WRES_ID_MGR=@p1 and WA.WPROJ_ID=@p0 and WTRANS_STATE<3 and WTRANS_ACTION=1 and WTRANS_TYPE<2 order by WWF.FIELD_ID RETURN
Select distinct WWF.FIELD_ID, 
                CUSTFIELD_TYPE, 
                WWORKGRP_INFO_IS_READONLY 
  from MSP_WEB_ASSIGNMENTS WA 
       INNER JOIN MSP_WEB_TRANSACTIONS WT 
          ON WA.WASSN_ID = WT.WASSN_ID 
       INNER JOIN MSP_WEB_PROJECT_WORKGROUP_INFO WPWI
          ON WA.WPROJ_ID = WPWI.WPROJ_ID
       INNER JOIN MSP_WEB_WORKGROUP_FIELDS_INFO WWFI 
          ON WPWI.CUSTFIELD_INFO_ID = WWFI.CUSTFIELD_INFO_ID
       INNER JOIN MSP_WEB_WORKGROUP_FIELDS WWF
          ON (WWFI.FIELD_ID = WWF.FIELD_ID and WA.WASSN_ID=WWF.WASSN_ID)
 where WA.WRES_ID_MGR = @p1 
   and WA.WPROJ_ID = @p0 
   and WTRANS_STATE < 3 
   and WTRANS_ACTION = 1 
   and (WTRANS_TYPE < 1 - @p2 or WTRANS_TYPE = @p2) 
 order by WWF.FIELD_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetAllCustomFieldsForTaskUpdates TO MSProjectServerRole
GO



/* Query #335108 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetNonPendingDelegationForProjUpdate
   @p0 INT,
   @p1 INT
AS
--Select MSP_WEB_ASSIGNMENTS.WASSN_ID,TASK_NAME,ASSN_WORK,ASSN_REM_WORK,RES_NAME,TASK_UID,ASSN_UID,WRES_ID_TEAM_LEAD,WLOCAL_PATH from MSP_WEB_ASSIGNMENTS,MSP_WEB_PROJECTS,MSP_WEB_RESOURCES,MSP_WEB_TRANSACTIONS where MSP_WEB_ASSIGNMENTS.WPROJ_ID=MSP_WEB_PROJECTS.WPROJ_ID and MSP_WEB_ASSIGNMENTS.WRES_ID=MSP_WEB_RESOURCES.WRES_ID and MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_TRANSACTIONS.WASSN_ID and WRES_ID_MGR=@p1 and WASSN_IS_DELEGATED<>0 and WASSN_DELEG_PENDING=0 and WASSN_DELETED_IN_PROJ=0 and MSP_WEB_ASSIGNMENTS.WPROJ_ID=@p0 and WTRANS_STATE<3 and WTRANS_ACTION=1 and WTRANS_TYPE=3 Order by MSP_WEB_ASSIGNMENTS.WRES_ID RETURN
-- Conversion to ANSI INNER JOIN
Select MSP_WEB_ASSIGNMENTS.WASSN_ID, 
       TASK_NAME, 
       ASSN_WORK, 
       ASSN_REM_WORK, 
       RES_NAME, 
       TASK_UID, 
       ASSN_UID, 
       WRES_ID_TEAM_LEAD, 
       WLOCAL_PATH 
  from MSP_WEB_ASSIGNMENTS 
       INNER JOIN MSP_WEB_PROJECTS 
          ON MSP_WEB_ASSIGNMENTS.WPROJ_ID = MSP_WEB_PROJECTS.WPROJ_ID 
       INNER JOIN MSP_WEB_RESOURCES 
          ON MSP_WEB_ASSIGNMENTS.WRES_ID = MSP_WEB_RESOURCES.WRES_ID 
       INNER JOIN MSP_WEB_TRANSACTIONS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID 
 where WRES_ID_MGR = @p1 
   and WASSN_IS_DELEGATED <> 0 
   and WASSN_DELEG_PENDING = 0 
   and WASSN_DELETED_IN_PROJ = 0 
   and MSP_WEB_ASSIGNMENTS.WPROJ_ID = @p0 
   and WTRANS_STATE < 3 
   and WTRANS_ACTION = 1 
   and WTRANS_TYPE = 3 
 Order by MSP_WEB_ASSIGNMENTS.WRES_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetNonPendingDelegationForProjUpdate TO MSProjectServerRole
GO



/* Query #335109 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetAssignmentInfoForRes
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT,
   @p4 INT
AS
--Select min(WWORK_START) as WWORK_START,max(WWORK_FINISH) as WWORK_FINISH from MSP_WEB_WORK,MSP_WEB_ASSIGNMENTS WA,MSP_WEB_TRANSACTIONS where MSP_WEB_WORK.WASSN_ID=WA.WASSN_ID and WA.WASSN_ID=MSP_WEB_TRANSACTIONS.WASSN_ID and WA.WPROJ_ID=@p0 and WRES_ID_MGR=@p1 and WA.WRES_ID=@p2 and WWORK_TYPE>0 and WTRANS_STATE<3 and WTRANS_ACTION=1 and WTRANS_TYPE<2 RETURN
-- Conversion to ANSI INNER JOIN
Select min(WWORK_START) as WWORK_START, 
       max(WWORK_FINISH) as WWORK_FINISH 
  from MSP_WEB_WORK 
       INNER JOIN MSP_WEB_ASSIGNMENTS WA 
          ON MSP_WEB_WORK.WASSN_ID = WA.WASSN_ID 
       INNER JOIN MSP_WEB_TRANSACTIONS 
          ON WA.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID
       INNER JOIN MSP_WEB_PROJECTS WP
	      ON WA.WPROJ_ID = WP.WPROJ_ID 
 where WA.WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1 
   and WA.WRES_ID = @p2 
   and (@p4=1 or WWORK_TYPE > 0)
   and WTRANS_STATE < 3 
   and WTRANS_ACTION = 1 
   and (WTRANS_TYPE < 1 - @p3 or WTRANS_TYPE = @p3) 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetAssignmentInfoForRes TO MSProjectServerRole
GO



/* Query #335110 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetAllResourcesForTaskUpdates
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
--Select distinct MSP_WEB_ASSIGNMENTS.WRES_ID,RES_NAME from MSP_WEB_ASSIGNMENTS,MSP_WEB_TRANSACTIONS,MSP_WEB_RESOURCES where MSP_WEB_ASSIGNMENTS.WASSN_ID=MSP_WEB_TRANSACTIONS.WASSN_ID and MSP_WEB_ASSIGNMENTS.WRES_ID=MSP_WEB_RESOURCES.WRES_ID and WPROJ_ID=@p0 and WRES_ID_MGR=@p1 and WTRANS_STATE<3 and WTRANS_ACTION=1 and WTRANS_TYPE<2 RETURN
-- Conversion to ANSI INNER JOIN
Select distinct MSP_WEB_ASSIGNMENTS.WRES_ID, 
                RES_NAME 
  from MSP_WEB_ASSIGNMENTS 
       INNER JOIN MSP_WEB_TRANSACTIONS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID 
       INNER JOIN MSP_WEB_RESOURCES 
          ON MSP_WEB_ASSIGNMENTS.WRES_ID = MSP_WEB_RESOURCES.WRES_ID 
 where WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1 
   and WTRANS_STATE < 3 
   and WTRANS_ACTION = 1 
   and (WTRANS_TYPE < 1 - @p2 or WTRANS_TYPE = @p2)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetAllResourcesForTaskUpdates TO MSProjectServerRole
GO


/* Query #335205 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_SetTransStateToUpdatedForRules
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT,
   @p4 DATETIME,
   @p6 NTEXT
AS
UPDATE MSP_WEB_TRANSACTIONS 
   SET WTRANS_STATE = @p3, 
       WTRANS_PROJ_UPDATE_DATE = @p4,
       WTRANS_ACTION = 1
 WHERE WTRANS_STATE < 2 
   and WTRANS_TYPE = @p2 
   and WASSN_ID in (SELECT WASSN_ID 
                      FROM MSP_WEB_ASSIGNMENTS
                           INNER JOIN dbo.MSP_WEB_FN_ConvertListToTable(@p6) LT ON WASSN_ID=LT.TokenVal
                     WHERE WRES_ID_MGR = @p0 
                       and WPROJ_ID = @p1)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_SetTransStateToUpdatedForRules TO MSProjectServerRole
GO


/* Query #335206 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetTasksUpdatesForResForRules
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT,
   @p4 NTEXT
AS
Select WA.WASSN_ID, 
       ASSN_UID, 
       WRES_ID, 
       TASK_NAME, 
       WASSN_PCT_COMP, 
       WASSN_CURRENT_TRACKING_MODE, 
       WASSN_UPDATE_TRACKING_MODE, 
       ASSN_START_DATE, 
       ASSN_FINISH_DATE, 
       ASSN_WORK, 
       ASSN_REM_WORK, 
       WASSN_COMMENTS, 
       WASSN_IS_CONFIRMED, 
       WASSN_DELETED_IN_PROJ, 
       WASSN_SEND_UPDATE_NEEDED 
  From MSP_WEB_ASSIGNMENTS WA 
       INNER JOIN MSP_WEB_TRANSACTIONS WT 
          ON WA.WASSN_ID = WT.WASSN_ID 
 Where WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1 
   and WRES_ID = @p2 
   and TASK_IS_SUMMARY = 0 
   and WTRANS_STATE < 3 
   and (WTRANS_TYPE < 1 - @p3 or WTRANS_TYPE = @p3) 
   and WA.WASSN_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p4)) 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetTasksUpdatesForResForRules TO MSProjectServerRole
GO


/* Query #335207 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetAllCustomFieldsForTaskUpdatesForRules
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 NTEXT
AS

Select distinct WWF.FIELD_ID, 
                CUSTFIELD_TYPE, 
                WWORKGRP_INFO_IS_READONLY 
  from MSP_WEB_ASSIGNMENTS WA 
       INNER JOIN MSP_WEB_TRANSACTIONS WT 
          ON WA.WASSN_ID = WT.WASSN_ID 
       INNER JOIN MSP_WEB_PROJECT_WORKGROUP_INFO WPWI
          ON WA.WPROJ_ID = WPWI.WPROJ_ID
       INNER JOIN MSP_WEB_WORKGROUP_FIELDS_INFO WWFI 
          ON WPWI.CUSTFIELD_INFO_ID = WWFI.CUSTFIELD_INFO_ID
       INNER JOIN MSP_WEB_WORKGROUP_FIELDS WWF
          ON (WWFI.FIELD_ID = WWF.FIELD_ID and WA.WASSN_ID=WWF.WASSN_ID)
 where WA.WRES_ID_MGR = @p1 
   and WA.WPROJ_ID = @p0 
   and WTRANS_STATE < 3 
   and WA.WASSN_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p3)) 
   and (WTRANS_TYPE < 1 - @p2 or WTRANS_TYPE = @p2)
 order by WWF.FIELD_ID
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetAllCustomFieldsForTaskUpdatesForRules TO MSProjectServerRole
GO


/* Query #335209 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetAssignmentInfoForResForRules
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT,
   @p4 INT,
   @p5 NTEXT
AS
Select min(WWORK_START) as WWORK_START, 
       max(WWORK_FINISH) as WWORK_FINISH 
  from MSP_WEB_WORK 
       INNER JOIN MSP_WEB_ASSIGNMENTS WA 
          ON MSP_WEB_WORK.WASSN_ID = WA.WASSN_ID 
       INNER JOIN MSP_WEB_TRANSACTIONS 
          ON WA.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID 
       INNER JOIN MSP_WEB_PROJECTS WP
          ON WA.WPROJ_ID = WP.WPROJ_ID 
 where WA.WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1 
   and WA.WRES_ID = @p2 
   and (@p4=1 or WWORK_TYPE > 0) 
   and WTRANS_STATE < 3 
   and WA.WASSN_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p5)) 
   and (WTRANS_TYPE < 1 - @p3 or WTRANS_TYPE = @p3) 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetAssignmentInfoForResForRules TO MSProjectServerRole
GO


/* Query #335210 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_GetAllResourcesForTaskUpdatesForRules
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 NTEXT
AS
Select distinct MSP_WEB_ASSIGNMENTS.WRES_ID, 
                RES_NAME 
  from MSP_WEB_ASSIGNMENTS 
       INNER JOIN MSP_WEB_TRANSACTIONS 
          ON MSP_WEB_ASSIGNMENTS.WASSN_ID = MSP_WEB_TRANSACTIONS.WASSN_ID 
       INNER JOIN MSP_WEB_RESOURCES 
          ON MSP_WEB_ASSIGNMENTS.WRES_ID = MSP_WEB_RESOURCES.WRES_ID 
 where WPROJ_ID = @p0 
   and WRES_ID_MGR = @p1 
   and WTRANS_STATE < 3 
   and MSP_WEB_ASSIGNMENTS.WASSN_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p3)) 
   and (WTRANS_TYPE < 1 - @p2 or WTRANS_TYPE = @p2) 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_GetAllResourcesForTaskUpdatesForRules TO MSProjectServerRole
GO


/* Query #335211 */
CREATE PROCEDURE dbo.MSP_WEB_SP_CHK_SetTaskUpdateTransStateToUpdatedForRules
   @p0 INT,
   @p1 NTEXT,
   @p4 INT,
   @p5 DATETIME,
   @p6 INT
AS
UPDATE MSP_WEB_TRANSACTIONS 
SET WTRANS_STATE=@p4,WTRANS_PROJ_UPDATE_DATE=@p5,WTRANS_ACTION=1 
WHERE WTRANS_STATE<2 
and (WTRANS_TYPE < 1 - @p6 or WTRANS_TYPE = @p6) 
and WASSN_ID in (
                 SELECT WA.WASSN_ID 
                 FROM MSP_WEB_ASSIGNMENTS WA 
                 WHERE WA.WASSN_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p1)) 
                       and WA.WRES_ID_MGR=@p0) 
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_CHK_SetTaskUpdateTransStateToUpdatedForRules TO MSProjectServerRole
GO


/* Query #345000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetTaskListAllFields
   @p0 INT
AS
Select
	WA.WASSN_NOTE_STATUS,
	WASSN_SEND_UPDATE_NEEDED,
	WASSN_UPDATE_STATUS,
	WASSN_REMOVED_BY_RESOURCE,
	WASSN_ID,
	WA.WRES_ID,
	TASK_NAME,
	WRES_ID_MGR,
	WA.WPROJ_ID,
	PROJ_NAME,
	WASSN_PCT_COMP,
	WASSN_CURRENT_TRACKING_MODE,
	ASSN_START_DATE,
	ASSN_FINISH_DATE,
	WASSN_COMMENTS,
	WP.WPROJ_TYPE,
	ASSN_WORK,
	ASSN_REM_WORK,
	WASSN_IS_NEW_ASSN
From 
	MSP_WEB_ASSIGNMENTS WA, 
	MSP_WEB_PROJECTS WP --This should probably be a join
Where 
	WA.WPROJ_ID = WP.WPROJ_ID AND 
	WP.WRES_ID = @p0 AND 
	WP.WPROJ_TYPE = 3 AND 
	TASK_ID<0 
Order By 
	TASK_NAME 

RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetTaskListAllFields TO MSProjectServerRole
GO



/* Query #16070 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectViewSuccessors10
   @p1 INT
AS
SELECT TaskUniqueID,SuccessorTaskUniqueID,SuccessorType FROM MSP_VIEW_PROJ_SUCC WHERE WPROJ_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectViewSuccessors10 TO MSProjectServerRole
GO



/* Query #16071 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectViewSuccessors10Ent
   @p1 INT
AS
SELECT TaskUniqueID,SuccessorTaskUniqueID,SuccessorType FROM MSP_VIEW_PROJ_SUCC WHERE WPROJ_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectViewSuccessors10Ent TO MSProjectServerRole
GO



/* Query #16073 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectViewSplits10
   @p1 INT
AS
Select TaskUniqueID,SplitStart,SplitFinish FROM MSP_VIEW_PROJ_TASKSPLITS WHERE WPROJ_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectViewSplits10 TO MSProjectServerRole
GO



/* Query #16074 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectViewSplits10Ent
   @p1 INT
AS
Select TaskUniqueID,SplitStart,SplitFinish FROM MSP_VIEW_PROJ_TASKSPLITS WHERE WPROJ_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectViewSplits10Ent TO MSProjectServerRole
GO



/* Query #16076 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectViewProjectInfo10
   @p1 INT
AS
SELECT ProjectDefaultStartTime,ProjectDefaultFinishTime,ProjectCurrencySymbol,ProjectCurrencyPosition,ProjectCurrencyDigits From MSP_VIEW_PROJ_PROJECTS_STD WHERE WPROJ_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectViewProjectInfo10 TO MSProjectServerRole
GO



/* Query #16077 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectViewProjectInfo10Ent
   @p1 INT
AS
SELECT ProjectDefaultStartTime,ProjectDefaultFinishTime,ProjectCurrencySymbol,ProjectCurrencyPosition,ProjectCurrencyDigits From MSP_VIEW_PROJ_PROJECTS_STD WHERE WPROJ_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectViewProjectInfo10Ent TO MSProjectServerRole
GO



/* Query #30011 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllTasksForProjIDForResources
   @p0 INT,
   @p1 INT,
   @p2 NTEXT
AS

SELECT TaskUniqueID as TASK_UID, TaskID as TASK_ID, 0 as WRES_ID, TaskName as TASK_NAME, TaskSummary as TASK_IS_SUMMARY, TaskOutlineLevel 
FROM MSP_VIEW_PROJ_TASKS_STD VPTS LEFT JOIN MSP_WEB_ASSIGNMENTS WA ON (VPTS.WPROJ_ID=WA.WPROJ_ID and VPTS.TaskUniqueID=WA.TASK_UID)
WHERE VPTS.WPROJ_ID=@p0 and TaskUniqueID>0 and WRES_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p2))
and TaskUniqueID not in (	SELECT DISTINCT WA2.TASK_UID 
							FROM MSP_WEB_ASSIGNMENTS WA2 
							WHERE WA2.WRES_ID=@p1 and WA2.WPROJ_ID=@p0 and WASSN_DELETED_IN_PROJ=0 and WASSN_REMOVED_BY_RESOURCE=0)
UNION
SELECT TaskUniqueID as TASK_UID, TaskID as TASK_ID, WRES_ID, TaskName as TASK_NAME, TaskSummary as TASK_IS_SUMMARY, TaskOutlineLevel
FROM MSP_VIEW_PROJ_TASKS_STD VPTS LEFT JOIN MSP_WEB_ASSIGNMENTS WA ON (VPTS.WPROJ_ID=WA.WPROJ_ID and VPTS.TaskUniqueID=WA.TASK_UID)
WHERE WRES_ID=@p1 and WASSN_DELETED_IN_PROJ=0 and WASSN_REMOVED_BY_RESOURCE=0 and VPTS.WPROJ_ID=@p0 and TaskUniqueID>0 and TASK_UID<>TASK_UID_SUMMARY

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllTasksForProjIDForResources TO MSProjectServerRole
GO



/* Query #30012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllTasksForProjIDForResourcesNotMe
   @p0 INT,
   @p1 INT,
   @p2 NTEXT
AS

SELECT DISTINCT TaskUniqueID as TASK_UID, TaskID as TASK_ID, 0 as WRES_ID, TaskName as TASK_NAME, TaskSummary as TASK_IS_SUMMARY, TaskOutlineLevel 
FROM MSP_VIEW_PROJ_TASKS_STD VPTS LEFT JOIN MSP_WEB_ASSIGNMENTS WA ON (VPTS.WPROJ_ID=WA.WPROJ_ID and VPTS.TaskUniqueID=WA.TASK_UID)
WHERE VPTS.WPROJ_ID=@p0 and TaskUniqueID>0 and WRES_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p2))

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllTasksForProjIDForResourcesNotMe TO MSProjectServerRole
GO




/* Query #30022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetTLFavorites
   @p0 INT,
   @p1 INT
AS
SELECT WVF.WVIEW_FAV_ID, WVF.WPROJ_ID, WVF.WVIEW_FAV_NAME, WVF.WVIEW_FAV_URL, WP.PROJ_NAME From MSP_WEB_VIEW_FAVORITES WVF, MSP_WEB_PROJECTS WP Where WVF.WRES_ID=(@p0) and WVF.WVIEW_TYPE=(@p1) and WVF.WPROJ_ID=WP.WPROJ_ID Order By WP.PROJ_NAME, WVF.WVIEW_FAV_NAME RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetTLFavorites TO MSProjectServerRole
GO



/* Query #30023 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllTasksForProjID
   @p0 INT,
   @p1 INT
AS

SELECT TaskUniqueID as TASK_UID, TaskID as TASK_ID, 0 as WRES_ID, TaskName as TASK_NAME, TaskSummary as TASK_IS_SUMMARY, TaskOutlineLevel 
FROM MSP_VIEW_PROJ_TASKS_STD VPTS LEFT JOIN MSP_WEB_ASSIGNMENTS WA ON (VPTS.WPROJ_ID=WA.WPROJ_ID and VPTS.TaskUniqueID=WA.TASK_UID)
WHERE VPTS.WPROJ_ID=@p0 and TaskUniqueID>0 
and TaskUniqueID not in (	SELECT DISTINCT WA2.TASK_UID 
							FROM MSP_WEB_ASSIGNMENTS WA2 
							WHERE WA2.WRES_ID=@p1 and WA2.WPROJ_ID=@p0 and WASSN_DELETED_IN_PROJ=0 and WASSN_REMOVED_BY_RESOURCE=0)
UNION
SELECT TaskUniqueID as TASK_UID, TaskID as TASK_ID, WRES_ID, TaskName as TASK_NAME, TaskSummary as TASK_IS_SUMMARY, TaskOutlineLevel
FROM MSP_VIEW_PROJ_TASKS_STD VPTS LEFT JOIN MSP_WEB_ASSIGNMENTS WA ON (VPTS.WPROJ_ID=WA.WPROJ_ID and VPTS.TaskUniqueID=WA.TASK_UID)
WHERE WRES_ID=@p1 and WASSN_DELETED_IN_PROJ=0 and WASSN_REMOVED_BY_RESOURCE=0 and VPTS.WPROJ_ID=@p0 and TaskUniqueID>0 and TASK_UID<>TASK_UID_SUMMARY

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllTasksForProjID TO MSProjectServerRole
GO



/* Query #30024 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMyProjectsAll
   @p0 INT
AS
SELECT
  DISTINCT WP.PROJ_NAME,
  WP.WPROJ_ID,
  WR.RES_NAME
FROM
  MSP_WEB_PROJECTS WP
  LEFT JOIN MSP_WEB_ASSIGNMENTS WA ON WA.WPROJ_ID=WP.WPROJ_ID AND WASSN_DELETED_IN_PROJ=0
  INNER JOIN MSP_WEB_RESOURCES WR ON WR.WRES_ID=WP.WRES_ID
WHERE
  (WA.WRES_ID=(@p0) or WA.WRES_ID_MGR=(@p0) or WP.WRES_ID=(@p0))
  and WP.WPROJ_TYPE<3
  and WP.WPROJ_DEFAULT_WPROJ_ID=WP.WPROJ_ID
  and WP.WPROJ_IS_NONWORKING=0
ORDER BY
  WP.WPROJ_ID
RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMyProjectsAll TO MSProjectServerRole
GO



/* Query #30025 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjNameTaskNameFromProjIdTaskId
   @p0 INT,
   @p1 INT
AS

SELECT WP.PROJ_NAME, WA.TASK_NAME 
FROM (MSP_WEB_ASSIGNMENTS WA INNER JOIN MSP_WEB_PROJECTS WP ON WA.WPROJ_ID=WP.WPROJ_ID) 
WHERE WA.WPROJ_ID=(@p0) and TASK_UID=(@p1) and TASK_UID<>TASK_UID_SUMMARY and TASK_UID>0 
UNION
SELECT WP.PROJ_NAME, TaskName as TASK_NAME
FROM (MSP_VIEW_PROJ_TASKS_STD PTS INNER JOIN MSP_WEB_PROJECTS WP ON PTS.WPROJ_ID=WP.WPROJ_ID) 
WHERE PTS.WPROJ_ID=(@p0) and TaskUniqueID=(@p1) and TaskUniqueID>0 

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjNameTaskNameFromProjIdTaskId TO MSProjectServerRole
GO



/* Query #30026 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllSTSServers
AS
SELECT * FROM MSP_WEB_STS_SERVERS RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllSTSServers TO MSProjectServerRole
GO



/* Query #30027 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCurrentSTSServerSettings
AS
SELECT WA.WADMIN_CURRENT_STS_SERVER_ID,
       WA.WADMIN_AUTO_CREATE_SUBWEBS,
       WA.WADMIN_AUTO_ADD_USER_TO_SUBWEB,
       WA.WADMIN_AUTO_ADD_USER_AS_ADV_AUTHOR_TO_SUBWEB,
       WA.WADMIN_PUBDOCS_STS_SUBWEB_NAME,
       WA.WADMIN_STS_TEMPLATE_LCID,
       WA.WADMIN_STS_TEMPLATE_ID,
       WA.WADMIN_STS_PRIMARY_OWNER_EMAIL,
       WA.WADMIN_STS_SECONDARY_OWNER_NAME,
       WA.WADMIN_STS_SECONDARY_OWNER_EMAIL,
       WA.WADMIN_STS_PORTAL_URL,
       WA.WADMIN_STS_PORTAL_NAME,
       WS.*
FROM MSP_WEB_ADMIN WA INNER JOIN MSP_WEB_STS_SERVERS WS 
   ON WS.WSTS_SERVER_ID=WA.WADMIN_CURRENT_STS_SERVER_ID
 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCurrentSTSServerSettings TO MSProjectServerRole
GO



/* Query #30028 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateCurrentSTSServerSettings
   @p0 INT,
   @p1 TINYINT,
   @p2 TINYINT,
   @p3 TINYINT,
   @p4 INT,
   @p5 NVARCHAR(50),
   @p6 NVARCHAR(100),
   @p7 NVARCHAR(100),
   @p8 NVARCHAR(100)
AS
UPDATE MSP_WEB_ADMIN 
   SET WADMIN_CURRENT_STS_SERVER_ID=(@p0),
       WADMIN_AUTO_CREATE_SUBWEBS=(@p1),
       WADMIN_AUTO_ADD_USER_TO_SUBWEB=(@p2),
       WADMIN_AUTO_ADD_USER_AS_ADV_AUTHOR_TO_SUBWEB=(@p3),
       WADMIN_STS_TEMPLATE_LCID=(@p4),
       WADMIN_STS_TEMPLATE_ID=(@p5),
       WADMIN_STS_PRIMARY_OWNER_EMAIL=NullIf(@p6,''),
       WADMIN_STS_SECONDARY_OWNER_NAME=NullIf(@p7,''),
       WADMIN_STS_SECONDARY_OWNER_EMAIL=NullIf(@p8,'')
   RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateCurrentSTSServerSettings TO MSProjectServerRole
GO



/* Query #30029 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetCurrentSTSServerNameAndAdminPort
AS
SELECT WS.*, WA.WADMIN_STS_TEMPLATE_LCID, WA.WADMIN_STS_TEMPLATE_ID FROM (MSP_WEB_STS_SERVERS WS INNER JOIN MSP_WEB_ADMIN WA ON WS.WSTS_SERVER_ID=WA.WADMIN_CURRENT_STS_SERVER_ID) RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetCurrentSTSServerNameAndAdminPort TO MSProjectServerRole
GO



/* Query #30030 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllProjectsWithNoSubweb
AS
SELECT WPROJ_ID, PROJ_NAME FROM MSP_WEB_PROJECTS WHERE (WPROJ_STS_SUBWEB_NAME=(N'NONE') OR WSTS_SERVER_ID=0) AND WPROJ_TYPE<>3 AND WPROJ_DEFAULT_WPROJ_ID=WPROJ_ID ORDER BY PROJ_NAME RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllProjectsWithNoSubweb TO MSProjectServerRole
GO



/* Query #30031 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjNameFromProjId
   @p0 INT
AS
SELECT PROJ_NAME, WPROJ_TYPE, WRES_ID FROM MSP_WEB_PROJECTS WHERE WPROJ_ID=(@p0) RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjNameFromProjId TO MSProjectServerRole
GO



/* Query #30032 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateDBCreateDeleteSubweb
   @p0 NVARCHAR(128),
   @p1 INT,
   @p2 INT,
   @p3 UNIQUEIDENTIFIER,
   @p4 UNIQUEIDENTIFIER
AS
UPDATE MSP_WEB_PROJECTS SET WPROJ_STS_SUBWEB_NAME=(@p0), WSTS_SERVER_ID=(@p1), WPROJ_ISSUE_LIST_NAME=NullIf(@p3,'{00000000-0000-0000-0000-000000000000}'), WPROJ_RISK_LIST_NAME=NullIf(@p4,'{00000000-0000-0000-0000-000000000000}') WHERE WPROJ_ID=(@p2) RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateDBCreateDeleteSubweb TO MSProjectServerRole
GO



/* Query #30033 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSubwebNServerNameForProjID
   @p0 INT
AS
SELECT WP.PROJ_NAME, WP.WPROJ_STS_SUBWEB_NAME, WS.* FROM (MSP_WEB_PROJECTS WP INNER JOIN MSP_WEB_STS_SERVERS WS ON WP.WSTS_SERVER_ID=WS.WSTS_SERVER_ID) WHERE WP.WPROJ_ID=(@p0) RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSubwebNServerNameForProjID TO MSProjectServerRole
GO



/* Query #30034 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetPublicDocsServerNSubwebName
AS

SELECT WS.*, WA.WADMIN_PUBDOCS_STS_SUBWEB_NAME, WA.WADMIN_STS_TEMPLATE_LCID FROM (MSP_WEB_ADMIN WA INNER JOIN MSP_WEB_STS_SERVERS WS ON WA.WADMIN_CURRENT_STS_SERVER_ID=WS.WSTS_SERVER_ID) RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetPublicDocsServerNSubwebName TO MSProjectServerRole
GO




/* Query #30035 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllTasksForProjIDForMe
   @p0 INT,
   @p1 INT
AS

SELECT DISTINCT TaskUniqueID as TASK_UID, TaskID as TASK_ID, WRES_ID, TaskName as TASK_NAME, TaskSummary as TASK_IS_SUMMARY, TaskOutlineLevel
FROM MSP_VIEW_PROJ_TASKS_STD VPTS LEFT JOIN MSP_WEB_ASSIGNMENTS WA ON (VPTS.WPROJ_ID=WA.WPROJ_ID and VPTS.TaskUniqueID=WA.TASK_UID)
WHERE WRES_ID=@p1 and WASSN_DELETED_IN_PROJ=0 and WASSN_REMOVED_BY_RESOURCE=0 and VPTS.WPROJ_ID=@p0 and TaskUniqueID>0 and TASK_UID<>TASK_UID_SUMMARY

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllTasksForProjIDForMe TO MSProjectServerRole
GO



/* Query #30036 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllResourceNamesForProjID
   @p0 INT
AS

SELECT DISTINCT
 WA.WRES_ID,
 WR.WRES_USE_NT_LOGON,
 WR.WRES_IS_ENABLED,
 WR.WRES_CAN_LOGIN,
 WR.WRES_COUNT_LICENSE,
 WR.WRES_EMAIL,
 WR.WRES_NT_ACCOUNT,
 WR.RES_NAME
FROM (MSP_WEB_ASSIGNMENTS WA INNER JOIN MSP_WEB_RESOURCES WR ON WA.WRES_ID=WR.WRES_ID) 
WHERE (WR.WRES_USE_NT_LOGON=1 and WR.WRES_IS_ENABLED=1 and WR.WRES_CAN_LOGIN=1 and WR.WRES_COUNT_LICENSE=1 and WA.WPROJ_ID=(@p0) and WA.WASSN_DELETED_IN_PROJ=0) 
UNION 
SELECT DISTINCT
 WA.WRES_ID_TEAM_LEAD,
 WR.WRES_USE_NT_LOGON,
 WR.WRES_IS_ENABLED,
 WR.WRES_CAN_LOGIN,
 WR.WRES_COUNT_LICENSE,
 WR.WRES_EMAIL,
 WR.WRES_NT_ACCOUNT,
 WR.RES_NAME
FROM (MSP_WEB_ASSIGNMENTS WA INNER JOIN MSP_WEB_RESOURCES WR ON WA.WRES_ID_TEAM_LEAD=WR.WRES_ID) 
WHERE (WR.WRES_USE_NT_LOGON=1 and WR.WRES_IS_ENABLED=1 and WR.WRES_CAN_LOGIN=1 and WR.WRES_COUNT_LICENSE=1 and WA.WPROJ_ID=(@p0) and WA.WASSN_DELETED_IN_PROJ=0)
 RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllResourceNamesForProjID TO MSProjectServerRole
GO



/* Query #30037 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetManagerNameForProjID
   @p0 INT
AS

SELECT DISTINCT
 WA.WRES_ID_MGR,
 WR.WRES_USE_NT_LOGON,
 WR.WRES_IS_ENABLED,
 WR.WRES_CAN_LOGIN,
 WR.WRES_COUNT_LICENSE,
 WR.WRES_EMAIL,
 WR.WRES_NT_ACCOUNT,
 WR.RES_NAME
FROM (MSP_WEB_ASSIGNMENTS WA INNER JOIN MSP_WEB_RESOURCES WR ON WA.WRES_ID_MGR=WR.WRES_ID) 
WHERE (WA.WPROJ_ID=(@p0) and
       WR.WRES_USE_NT_LOGON=1 and
       WR.WRES_IS_ENABLED=1 and
       WR.WRES_CAN_LOGIN=1 and
       WR.WRES_COUNT_LICENSE=1)
UNION 
SELECT DISTINCT
 WP.WRES_ID,
 WR.WRES_USE_NT_LOGON,
 WR.WRES_IS_ENABLED,
 WR.WRES_CAN_LOGIN,
 WR.WRES_COUNT_LICENSE,
 WR.WRES_EMAIL,
 WR.WRES_NT_ACCOUNT,
 WR.RES_NAME
FROM (MSP_WEB_PROJECTS WP INNER JOIN MSP_WEB_RESOURCES WR ON WP.WRES_ID=WR.WRES_ID) 
WHERE (WP.WPROJ_ID=(@p0) and
       WR.WRES_USE_NT_LOGON=1 and
       WR.WRES_IS_ENABLED=1 and
       WR.WRES_CAN_LOGIN=1 and
       WR.WRES_COUNT_LICENSE=1)
RETURN

GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetManagerNameForProjID TO MSProjectServerRole
GO



/* Query #35100 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetMenuInfoForPageID
   @p0 INT
AS
SELECT WSEC_MENU_ID,WSEC_MENU_PARENT_ID,WSEC_PAGE_ACT_ID,WSEC_PAGE_MASTER_PAGE_ID,WSEC_PAGE_HELP_URL 
FROM MSP_WEB_SECURITY_PAGES WSP INNER JOIN MSP_WEB_SECURITY_MENUS WSM ON WSP.WSEC_PAGE_MENU_ID=WSM.WSEC_MENU_ID 
WHERE WSEC_PAGE_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetMenuInfoForPageID TO MSProjectServerRole
GO



/* Query #40000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetTaskNoteForDialog
   @p0 INT,
   @p1 INT
AS

SELECT 
	p.PROJ_NAME AS Project,
	a.TASK_NAME AS Assignment,
	a.WASSN_COMMENTS AS [Current],
	a.WASSN_HISTORY_NOTES AS History 
FROM
  MSP_WEB_PROJECTS p 
INNER JOIN
  MSP_WEB_ASSIGNMENTS a ON p.WPROJ_ID = a.WPROJ_ID
WHERE (a.WASSN_ID = @p0)
AND
(
  (a.WRES_ID = @p1) OR
  (a.WRES_ID_MGR = @p1) OR
  (a.WRES_ID IN
    (
    SELECT WRES_ID FROM MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p1, 212, - 1) r1
    UNION
    SELECT WRES_ID FROM MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p1, 510, - 1) r2
    )
  )
)
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetTaskNoteForDialog TO MSProjectServerRole
GO



/* Query #40001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetCurrentTaskNote
   @p0 NTEXT,
   @p1 INT,
   @p2 INT
AS
UPDATE MSP_WEB_ASSIGNMENTS
SET
  WASSN_COMMENTS = @p0,
  WASSN_SEND_UPDATE_NEEDED = 1,
  WASSN_NOTE_STATUS = 1
WHERE 
  (WASSN_ID = @p1)
AND
(
  (WRES_ID = @p2) OR
  (WRES_ID_MGR = @p2) OR
  (WRES_ID IN (SELECT WRES_ID FROM MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p2, 212, - 1) r1))
)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetCurrentTaskNote TO MSProjectServerRole
GO



/* Query #40002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetCurrentTaskNoteToNull
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
UPDATE MSP_WEB_ASSIGNMENTS
SET
  WASSN_COMMENTS = NULL,
  WASSN_NOTE_STATUS = @p0
WHERE
  (WASSN_ID = @p1)
AND
(
  (WRES_ID = @p2) OR
  (WRES_ID_MGR = @p2) OR
  (WRES_ID IN (SELECT WRES_ID FROM MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p2, 212, - 1) r1))
)
RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetCurrentTaskNoteToNull TO MSProjectServerRole
GO



/* Query #40003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetTaskNoteForDialogDelegate
   @p0 INT,
   @p1 INT
AS
SELECT 
  p.PROJ_NAME AS Project,
  a.TASK_NAME AS Assignment,
  a.WASSN_HISTORY_NOTES AS History
FROM
  MSP_WEB_PROJECTS p
  INNER JOIN MSP_WEB_ASSIGNMENTS a ON p.WPROJ_ID = a.WPROJ_ID
WHERE
  (a.WASSN_ID = @p0)
AND
(
  (a.WRES_ID = @p1) OR
  (a.WRES_ID_MGR = @p1) OR
  (a.WRES_ID IN
    (
    SELECT WRES_ID FROM MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p1, 212, - 1) r1
    UNION
    SELECT WRES_ID FROM MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(@p1, 510, - 1) r2
    )
  )
)

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetTaskNoteForDialogDelegate TO MSProjectServerRole
GO



/* Query #40004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_RemoveObject
   @p0 INT
AS
DELETE MSP_WEB_OBJECTS WHERE WOBJ_ID = @p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_RemoveObject TO MSProjectServerRole
GO



/* Query #40005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetObjectDetails
   @p0 INT
AS
SELECT * FROM MSP_WEB_OBJECTS WHERE WOBJ_ID = @p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetObjectDetails TO MSProjectServerRole
GO



/* Query #40007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_RemoveLink
   @p0 INT,
   @p1 INT
AS
DELETE MSP_WEB_OBJECT_LINKS WHERE (WOBJLINK_OBJECT1 = @p0 AND WOBJLINK_OBJECT2 = @p1) OR (WOBJLINK_OBJECT1 = @p1 AND WOBJLINK_OBJECT2 = @p0) RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_RemoveLink TO MSProjectServerRole
GO



/* Query #40009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectObjectID
   @p0 INT,
   @p1 INT
AS
SELECT WOBJ_ID FROM MSP_WEB_OBJECTS WHERE WOBJ_PROJ_ID = @p0 AND WOBJ_TYPE = @p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectObjectID TO MSProjectServerRole
GO



/* Query #40010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetTaskObjectID
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
SELECT WOBJ_ID FROM MSP_WEB_OBJECTS WHERE WOBJ_PROJ_ID = @p0 AND WOBJ_TASK_ID = @p1 AND WOBJ_TYPE = @p2 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetTaskObjectID TO MSProjectServerRole
GO



/* Query #40012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectObjectForInsert
   @p0 INT,
   @p1 INT
AS
SELECT WOBJ_ID, WOBJ_TYPE, WOBJ_PROJ_ID FROM MSP_WEB_OBJECTS WHERE WOBJ_PROJ_ID = @p0 AND WOBJ_TYPE = @p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectObjectForInsert TO MSProjectServerRole
GO



/* Query #40013 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetTaskObjectForInsert
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
SELECT WOBJ_ID, WOBJ_TYPE, WOBJ_PROJ_ID, WOBJ_TASK_ID  FROM MSP_WEB_OBJECTS WHERE WOBJ_PROJ_ID = @p0 AND WOBJ_TASK_ID = @p1 AND WOBJ_TYPE = @p2 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetTaskObjectForInsert TO MSProjectServerRole
GO



/* Query #40014 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSTSObjectID
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 UNIQUEIDENTIFIER
AS
SELECT WOBJ_ID FROM MSP_WEB_OBJECTS WHERE WOBJ_TYPE = @p0 AND WOBJ_PROJ_ID = @p1 AND WOBJ_TP_ID = @p2 AND WOBJ_LIST_NAME = @p3 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSTSObjectID TO MSProjectServerRole
GO



/* Query #40015 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetSTSObjectForInsert
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 UNIQUEIDENTIFIER
AS
SELECT WOBJ_ID, WOBJ_TYPE, WOBJ_PROJ_ID, WOBJ_TP_ID, WOBJ_LIST_NAME FROM MSP_WEB_OBJECTS WHERE WOBJ_TYPE = @p0 AND WOBJ_PROJ_ID = @p1 AND WOBJ_TP_ID = @p2 AND WOBJ_LIST_NAME = @p3 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetSTSObjectForInsert TO MSProjectServerRole
GO



/* Query #40016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetLinkedObjects
   @p0 INT
AS
SELECT WOBJLINK_OBJECT1, WOBJLINK_OBJECT2, WOBJLINK_TYPE 
FROM dbo.MSP_WEB_OBJECT_LINKS WITH (READPAST)
WHERE (WOBJLINK_OBJECT1 = @p0) OR (WOBJLINK_OBJECT2 = @p0) RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetLinkedObjects TO MSProjectServerRole
GO



/* Query #40017 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetLinkedObjectsOfLinkType
   @p0 INT,
   @p1 INT
AS
SELECT WOBJLINK_OBJECT1, WOBJLINK_OBJECT2, WOBJLINK_TYPE 
FROM dbo.MSP_WEB_OBJECT_LINKS WITH (READPAST)
WHERE ((WOBJLINK_OBJECT1 = @p0) OR (WOBJLINK_OBJECT2 = @p0)) AND WOBJLINK_TYPE=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetLinkedObjectsOfLinkType TO MSProjectServerRole
GO



/* Query #40018 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetLinkedObjectsOfObjType
   @p0 INT,
   @p1 INT
AS
SELECT WOBJLINK_OBJECT1, WOBJLINK_OBJECT2, WOBJLINK_TYPE 
FROM MSP_WEB_OBJECT_LINKS L WITH (READPAST)
INNER JOIN MSP_WEB_OBJECTS O ON L.WOBJLINK_OBJECT1 = O.WOBJ_ID 
WHERE L.WOBJLINK_OBJECT2 = @p0 AND O.WOBJ_TYPE=@p1 
UNION 
SELECT WOBJLINK_OBJECT1, WOBJLINK_OBJECT2, WOBJLINK_TYPE 
FROM MSP_WEB_OBJECT_LINKS L WITH (READPAST)
INNER JOIN MSP_WEB_OBJECTS O ON L.WOBJLINK_OBJECT2 = O.WOBJ_ID 
WHERE L.WOBJLINK_OBJECT1 = @p0 AND O.WOBJ_TYPE=@p1 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetLinkedObjectsOfObjType TO MSProjectServerRole
GO



/* Query #40019 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetLinkedObjectsOfLinkAndObjTypes
   @p0 INT,
   @p1 INT,
   @p2 INT
AS
SELECT WOBJLINK_OBJECT1, WOBJLINK_OBJECT2, WOBJLINK_TYPE 
FROM MSP_WEB_OBJECT_LINKS L WITH (READPAST)
INNER JOIN MSP_WEB_OBJECTS O ON L.WOBJLINK_OBJECT1 = O.WOBJ_ID WHERE L.WOBJLINK_OBJECT2 = @p0 AND L.WOBJLINK_TYPE = @p1 AND O.WOBJ_TYPE=@p2 
UNION 
SELECT WOBJLINK_OBJECT1, WOBJLINK_OBJECT2, WOBJLINK_TYPE 
FROM MSP_WEB_OBJECT_LINKS L WITH (READPAST)
INNER JOIN MSP_WEB_OBJECTS O ON L.WOBJLINK_OBJECT2 = O.WOBJ_ID WHERE L.WOBJLINK_OBJECT1 = @p0 AND L.WOBJLINK_TYPE = @p1 AND O.WOBJ_TYPE=@p2 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetLinkedObjectsOfLinkAndObjTypes TO MSProjectServerRole
GO


/* Query #40120 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetProjectEntOutlineCodeFields
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  SELECT
     MWVF.WFIELD_ID,
     MWC.CONV_STRING,
     MWVF.WFIELD_TEXTCONV_TYPE,
     MAS.AS_VALUE
  FROM
     MSP_WEB_VIEW_FIELDS MWVF 
     INNER JOIN MSP_WEB_CONVERSIONS MWC ON MWVF.WFIELD_NAME_CONV_VALUE = MWC.CONV_VALUE
     LEFT JOIN MSP_FIELD_ATTRIBUTES MFA ON (MWVF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
     LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS ON (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
  WHERE 
     MWC.LANG_ID = @p0
  AND
     MWVF.WFIELD_ID IN (
        188744589, 188744598, 188744599, 188744600, 188744601, 188744602, 188744603, 188744604, 188744605, 188744606,
        188744607, 188744590, 188744608, 188744609, 188744610, 188744611, 188744612, 188744613, 188744614, 188744615, 
        188744616, 188744617, 188744591, 188744618, 188744592, 188744593, 188744594, 188744595, 188744596, 188744597
     )
  ORDER BY MWC.CONV_STRING

RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetProjectEntOutlineCodeFields TO MSProjectServerRole
GO

/* Query #40121 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetFiltersForViewId
   @p0 INT
AS
BEGIN

SELECT
	WVIEW_FILTER_PARAM1, WVIEW_FILTER_PARAM2, WVIEW_FILTER_PARAM3
FROM
	MSP_WEB_VIEW_REPORTS
WHERE
	WVIEW_ID = @p0

RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetFiltersForViewId TO MSProjectServerRole
GO


/* Query #40022 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllDocsForIssuesEditForm
   @p0 INT,
   @p1 INT,
   @p2 INT,
   @p3 INT
AS
SELECT o.WOBJ_ID, o.WOBJ_TP_ID, o.WOBJ_LIST_NAME, (CASE WHEN l1.WOBJLINK_TYPE IS NOT NULL THEN l1.WOBJLINK_TYPE WHEN l2.WOBJLINK_TYPE IS NOT NULL THEN l2.WOBJLINK_TYPE ELSE 0 END) AS WOBJLINK_TYPE FROM MSP_WEB_OBJECTS o LEFT JOIN MSP_WEB_OBJECT_LINKS l1 ON o.WOBJ_ID = l1.WOBJLINK_OBJECT1 AND l1.WOBJLINK_OBJECT2 = (SELECT WOBJ_ID FROM MSP_WEB_OBJECTS WHERE WOBJ_PROJ_ID = @p0 AND WOBJ_TYPE = @p1 AND WOBJ_TP_ID = @p2) LEFT JOIN MSP_WEB_OBJECT_LINKS l2 ON o.WOBJ_ID = l2.WOBJLINK_OBJECT2 AND l2.WOBJLINK_OBJECT1 = (SELECT WOBJ_ID FROM MSP_WEB_OBJECTS WHERE WOBJ_PROJ_ID = @p0 AND WOBJ_TYPE = @p1 AND WOBJ_TP_ID = @p2) WHERE o.WOBJ_PROJ_ID = @p0 AND o.WOBJ_TYPE = @p3 ORDER BY o.WOBJ_LIST_NAME, o.WOBJ_TP_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllDocsForIssuesEditForm TO MSProjectServerRole
GO



/* Query #40024 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetLinkType
   @p0 INT,
   @p1 INT
AS
SELECT WOBJLINK_TYPE 
FROM MSP_WEB_OBJECT_LINKS WITH (READPAST)
WHERE (WOBJLINK_OBJECT1 = @p0 AND WOBJLINK_OBJECT2 = @p1) OR (WOBJLINK_OBJECT1 = @p1 AND WOBJLINK_OBJECT2 = @p0) RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetLinkType TO MSProjectServerRole
GO



/* Query #40025 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetObjectsForRefCntUpdate
   @p0 INT,
   @p1 INT
AS
SELECT WOBJ_ID,WOBJ_TYPE,WOBJ_DOC_REF_CNT,WOBJ_ISSUE_REF_CNT,WOBJ_RISK_REF_CNT,WOBJ_OTHER_REF_CNT FROM MSP_WEB_OBJECTS WHERE WOBJ_ID = @p0 OR WOBJ_ID = @p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetObjectsForRefCntUpdate TO MSProjectServerRole
GO



/* Query #45000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllGroupSchemes
AS
Select * From MSP_WEB_GROUP_SCHEMES Order By WGROUP_SCHEME_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllGroupSchemes TO MSProjectServerRole
GO



/* Query #45001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_RenameGroupScheme
   @p0 INT,
   @p1 NVARCHAR(50)
AS
Update MSP_WEB_GROUP_SCHEMES set WGROUP_SCHEME_NAME=@p1 Where WGROUP_SCHEME_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_RenameGroupScheme TO MSProjectServerRole
GO



/* Query #45002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetGroupSettingsForScheme
   @p0 INT
AS
Select * From MSP_WEB_GROUP_SETTINGS Where WGROUP_SCHEME_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetGroupSettingsForScheme TO MSProjectServerRole
GO



/* Query #45003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetDashboardURLByResID
   @p0 INT
AS
Select Distinct g.WSEC_GRP_DASHBOARD_URL From MSP_WEB_SECURITY_GROUPS g Inner Join (Select gm.WSEC_GRP_GUID From MSP_WEB_RESOURCES r Inner Join MSP_WEB_SECURITY_GROUP_MEMBERS gm On r.WRES_GUID = gm.WRES_GUID Where r.WRES_ID = @p0) rgm On g.WSEC_GRP_GUID = rgm.WSEC_GRP_GUID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetDashboardURLByResID TO MSProjectServerRole
GO



/* Query #54000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNumPendingTransForMgr
   @p0 INT
AS
select count(WTRANS_ID) as NumTrans from MSP_WEB_TRANSACTIONS WT inner join MSP_WEB_ASSIGNMENTS WA on WT.WASSN_ID=WA.WASSN_ID where WTRANS_STATE<2 and WRES_ID_MGR=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNumPendingTransForMgr TO MSProjectServerRole
GO



/* Query #54001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNumPendingTransForMgrAndProj
   @p0 INT,
   @p1 INT
AS
select count(WTRANS_ID) as NumTrans from MSP_WEB_TRANSACTIONS WT inner join MSP_WEB_ASSIGNMENTS WA on WT.WASSN_ID=WA.WASSN_ID where WTRANS_STATE<2 and WRES_ID_MGR=@p0 and WPROJ_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNumPendingTransForMgrAndProj TO MSProjectServerRole
GO



/* Query #54002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNumSRForMgr
   @p0 INT
AS
select count(WSR_ID) as NumSR from MSP_WEB_STATUS_REPORTS where WRES_ID_MGR=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNumSRForMgr TO MSProjectServerRole
GO



/* Query #54010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDefFileIDFromFileTimeStamp
   @p0 NVARCHAR(32),
   @p1 NVARCHAR(255)
AS
select WPROJ_ID from MSP_WEB_PROJECTS where PROJ_TIMESTAMP=@p0 and lower(PROJ_NAME)=lower(@p1) and WPROJ_ID=WPROJ_DEFAULT_WPROJ_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDefFileIDFromFileTimeStamp TO MSProjectServerRole
GO



/* Query #54014 */
CREATE  PROCEDURE dbo.MSP_WEB_SP_QRY_DeleteToDoListByID
  @p0 INT
AS
BEGIN
  -- Check To-Do List ID
  select WPROJ_TYPE from MSP_WEB_PROJECTS where WPROJ_ID=@p0 and WPROJ_TYPE=3
  if (@@ROWCOUNT <> 1) RETURN

  -- Delete all related data
  Delete From MSP_WEB_WORKGROUP_FIELDS where WASSN_ID in (select WASSN_ID from MSP_WEB_ASSIGNMENTS where WPROJ_ID=@p0)
  Delete From MSP_WEB_ASSIGNMENTS where WPROJ_ID=@p0
  Delete From MSP_WEB_PROJECTS where WPROJ_ID=@p0
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_DeleteToDoListByID to MSProjectServerRole
GO


/* Query #60000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDataSpace
   @p0 UNIQUEIDENTIFIER,
   @p1 INT
AS
select WSET_VALUE from MSP_WEB_RESOURCE_SETTINGS where WRES_GUID = @p0 and WSEC_PAGE_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDataSpace TO MSProjectServerRole
GO



/* Query #60002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateDataSpace
   @p0 UNIQUEIDENTIFIER,
   @p1 INT,
   @p2 NTEXT
AS
update MSP_WEB_RESOURCE_SETTINGS set WSET_VALUE = @p2 where WRES_GUID=@p0 and WSEC_PAGE_ID=@p1 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateDataSpace TO MSProjectServerRole
GO



/* Query #65005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
AS
select WADMIN_SMTP_SERVER_NAME, 
       WADMIN_SMTP_SERVER_PORT, 
       WADMIN_DEFAULT_LANGUAGE, 
       WADMIN_NTFY_FROM_EMAIL, 
       WADMIN_NTFY_EMAIL_TRAILER, 
       WADMIN_ORG_EMAIL_ADDRESS,
       WADMIN_NPE_LAST_RUN, 
       WADMIN_NPE_NEXT_RUN,
       WADMIN_NPE_SCHEDULED_TIME,
       WADMIN_INTRANET_SERVER_URL,
       WADMIN_EXTRANET_SERVER_URL
  from MSP_WEB_ADMIN 
  
  RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO MSProjectServerRole
GO



/* Query #65006 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetNotificationAdminInfo
   @p0 NVARCHAR(100),
   @p1 NVARCHAR(100),
   @p2 NVARCHAR(255),
   @p3 NVARCHAR(256),
   @p4 INT
AS
update MSP_WEB_ADMIN set WADMIN_ORG_EMAIL_ADDRESS=@p0, WADMIN_NTFY_FROM_EMAIL=@p1, WADMIN_NTFY_EMAIL_TRAILER=@p2, WADMIN_SMTP_SERVER_NAME=@p3, WADMIN_SMTP_SERVER_PORT=@p4 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetNotificationAdminInfo TO MSProjectServerRole
GO



/* Query #65007 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetUserEmailLanguage
   @p0 INT
AS
select case when WRES_EMAIL_LANGUAGE=0 then WADMIN_DEFAULT_LANGUAGE else WRES_EMAIL_LANGUAGE end as WRES_EMAIL_LANGUAGE from MSP_WEB_RESOURCES, MSP_WEB_ADMIN where WRES_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetUserEmailLanguage TO MSProjectServerRole
GO



/* Query #65008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetUserEmailLanguage
   @p0 INT,
   @p1 INT
AS
BEGIN
  if (EXISTS(select WLANG_LCID from MSP_WEB_INSTALLED_LANGUAGES where WLANG_LCID = @p0))
  Begin
    update MSP_WEB_RESOURCES set WRES_EMAIL_LANGUAGE=@p0 where WRES_ID=@p1 RETURN(0)
  End
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetUserEmailLanguage TO MSProjectServerRole
GO



/* Query #65009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetInstalledLanguages
   @p0 INT
AS
select L.WLANG_LCID, V.CONV_STRING from MSP_WEB_INSTALLED_LANGUAGES L, MSP_WEB_CONVERSIONS V where V.STRING_TYPE_ID=7 and V.LANG_ID=@p0 and L.CONV_VALUE=V.CONV_VALUE RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetInstalledLanguages TO MSProjectServerRole
GO



/* Query #65038 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetOrgMenuBar
   @p0 INT
AS
select WSEC_MENU_ID, CV1.CONV_STRING as WSEC_MENU_NAME, WSEC_MENU_CUSTOM_NAME, CV2.CONV_STRING as WSEC_MENU_DESC, WSEC_MENU_CUSTOM_DESC from MSP_WEB_SECURITY_MENUS MN left outer join MSP_WEB_CONVERSIONS CV1 ON MN.WSEC_MENU_NAME_ID=CV1.CONV_VALUE and CV1.LANG_ID=@p0 left outer join MSP_WEB_CONVERSIONS CV2 ON MN.WSEC_MENU_DESC_ID=CV2.CONV_VALUE and CV2.LANG_ID=@p0 Where MN.WSEC_MENU_PARENT_ID=-1 Order By WSEC_MENU_SEQ RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetOrgMenuBar TO MSProjectServerRole
GO



/* Query #65043 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllTemplates
AS
select * from MSP_WEB_SECURITY_TEMPLATES order by WSEC_TMPL_NAME RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllTemplates TO MSProjectServerRole
GO



/* Query #65044 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResNotificationsInUI
   @p0 INT
AS
select N.*, E.WNTFY_EVENT_ACTION_ID from MSP_WEB_NOTIFICATIONS N, MSP_WEB_NOTIFICATION_EVENTS E Where N.WNTFY_OWNER_ID=@p0 and E.WNTFY_EVENT_ID=N.WNTFY_EVENT_ID and E.WNTFY_EVENT_SHOW_UI=1 order by E.WNTFY_EVENT_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResNotificationsInUI TO MSProjectServerRole
GO



/* Query #65045 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationEventsInUI
AS
select * from MSP_WEB_NOTIFICATION_EVENTS where WNTFY_EVENT_SHOW_UI=1 Order By WNTFY_EVENT_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationEventsInUI TO MSProjectServerRole
GO



/* Query #65050 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminLicenses
AS
select WADMIN_LICENSES from MSP_WEB_ADMIN RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminLicenses TO MSProjectServerRole
GO



/* Query #65051 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetActiveUsersNumber
AS
select count(*) from MSP_WEB_RESOURCES where WRES_IS_ENABLED=1 and WRES_CAN_LOGIN=1 and WRES_COUNT_LICENSE=1 and dbo.MSP_WEB_FN_SEC_CheckSPGlobalPermission(WRES_GUID, 102)=1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetActiveUsersNumber TO MSProjectServerRole
GO



/* Query #65052 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_SetAdminLicenses
   @p0 INT
AS
update MSP_WEB_ADMIN set WADMIN_LICENSES=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_SetAdminLicenses TO MSProjectServerRole
GO



/* Query #66023 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetObjectRulesByCatIDAndObjID
   @p0 INT,
   @p1 INT
AS
select * from MSP_WEB_SECURITY_CATEGORY_RULES where WSEC_CAT_ID=@p0 and WSEC_OBJ_TYPE=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetObjectRulesByCatIDAndObjID TO MSProjectServerRole
GO



/* Query #66024 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResIDsWithGlobalPermission
   @p0 INT
AS
select WRES_ID, max(WSEC_ALLOW) as WSEC_ALLOW, max(WSEC_DENY) as WSEC_DENY, max(WSEC_ACCESS) as WSEC_ACCESS from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, MSP_WEB_SECURITY_GROUP_MEMBERS GM, MSP_WEB_RESOURCES R where WSEC_FEA_ACT_ID=@p0 and SCP.WSEC_REL_ID=SCR.WSEC_REL_ID and SCR.WSEC_CAT_ID=0 and SCR.WSEC_SP_GUID=GM.WSEC_GRP_GUID and GM.WRES_GUID=R.WRES_GUID group by WRES_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResIDsWithGlobalPermission TO MSProjectServerRole
GO


/*----------------------------------------------------------*/
/* Get all the res setting for doc permissions on a project */
/*----------------------------------------------------------*/
CREATE FUNCTION dbo.MSP_WEB_FN_SEC_GetResWithDocActIdOnProject(@ActID int, @ProjID int)
RETURNS @tbl table (WRES_ID int, WSEC_ALLOW smallint, WSEC_DENY smallint, WSEC_ACCESS smallint)
AS
BEGIN
   insert into @tbl (WRES_ID, WSEC_ALLOW, WSEC_DENY, WSEC_ACCESS)
   (
      select R1.WRES_ID , SCP1.WSEC_ALLOW , SCP1.WSEC_DENY , SCP1.WSEC_ACCESS 
        from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP1
             INNER JOIN MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR1 ON (SCP1.WSEC_FEA_ACT_ID=@ActID and SCP1.WSEC_REL_ID=SCR1.WSEC_REL_ID)
             INNER JOIN MSP_WEB_SECURITY_CATEGORY_RULES CR1    ON (SCR1.WSEC_CAT_ID=CR1.WSEC_CAT_ID and CR1.WSEC_OBJ_TYPE=1 and CR1.WSEC_OBJ_RULE_TYPE=0)
             INNER JOIN MSP_WEB_SECURITY_GROUP_MEMBERS GM1     ON (SCR1.WSEC_SP_GUID=GM1.WSEC_GRP_GUID)
             INNER JOIN MSP_WEB_RESOURCES R1                   ON (GM1.WRES_GUID=R1.WRES_GUID)

      UNION ALL

      select R.WRES_ID, SCP.WSEC_ALLOW, SCP.WSEC_DENY, SCP.WSEC_ACCESS
        from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP
             INNER JOIN MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR ON (SCP.WSEC_FEA_ACT_ID=@ActID and SCP.WSEC_REL_ID=SCR.WSEC_REL_ID)
             INNER JOIN MSP_WEB_SECURITY_CATEGORY_OBJECTS CO  ON (SCR.WSEC_CAT_ID=CO.WSEC_CAT_ID and CO.WSEC_OBJ_TYPE=1 and CO.WSEC_OBJ_ID=@ProjID)
             INNER JOIN MSP_WEB_SECURITY_GROUP_MEMBERS GM     ON (SCR.WSEC_SP_GUID=GM.WSEC_GRP_GUID)
             INNER JOIN MSP_WEB_RESOURCES R                   ON (GM.WRES_GUID=R.WRES_GUID)
   )
RETURN
END
GO

GRANT SELECT ON dbo.MSP_WEB_FN_SEC_GetResWithDocActIdOnProject TO MSProjectServerRole
GO


/* Query #66026 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetResWithDocActIDOnProject
   @p0 INT,
   @p1 INT
AS
Select WRES_ID, max(WSEC_ALLOW) as WSEC_ALLOW, max(WSEC_DENY) as WSEC_DENY, max(WSEC_ACCESS) as WSEC_ACCESS From dbo.MSP_WEB_FN_SEC_GetResWithDocActIdOnProject(@p0, @p1) Group By WRES_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetResWithDocActIDOnProject TO MSProjectServerRole
GO


/* Query #66027 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetCatOfAllProjThatAResHasDocPermission
   @p0 UNIQUEIDENTIFIER,
   @p1 INT
AS
select SCR.WSEC_CAT_ID, max(SCP.WSEC_ALLOW) as WSEC_ALLOW, max(SCP.WSEC_DENY) as WSEC_DENY, max(SCP.WSEC_ACCESS) as WSEC_ACCESS from MSP_WEB_SECURITY_GROUP_MEMBERS GM, MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, MSP_WEB_SECURITY_CATEGORY_RULES CR where GM.WRES_GUID=@p0 and GM.WSEC_GRP_GUID=SCR.WSEC_SP_GUID and SCR.WSEC_REL_ID=SCP.WSEC_REL_ID and SCP.WSEC_FEA_ACT_ID=@p1 and SCR.WSEC_CAT_ID=CR.WSEC_CAT_ID and CR.WSEC_OBJ_TYPE=1 and CR.WSEC_OBJ_RULE_TYPE=0 group by SCR.WSEC_CAT_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetCatOfAllProjThatAResHasDocPermission TO MSProjectServerRole
GO



/* Query #66028 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetCatOfProjectsThatAResHasDocPermission
   @p0 UNIQUEIDENTIFIER,
   @p1 INT
AS
select SCR.WSEC_CAT_ID, max(SCP.WSEC_ALLOW) as WSEC_ALLOW, max(SCP.WSEC_DENY) as WSEC_DENY, max(SCP.WSEC_ACCESS) as WSEC_ACCESS from MSP_WEB_SECURITY_GROUP_MEMBERS GM, MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, MSP_WEB_SECURITY_SP_CAT_PERMISSIONS SCP, MSP_WEB_SECURITY_CATEGORY_OBJECTS CO where GM.WRES_GUID=@p0 and GM.WSEC_GRP_GUID=SCR.WSEC_SP_GUID and SCR.WSEC_REL_ID=SCP.WSEC_REL_ID and SCP.WSEC_FEA_ACT_ID=@p1 and SCR.WSEC_CAT_ID=CO.WSEC_CAT_ID and CO.WSEC_OBJ_TYPE=1 group by SCR.WSEC_CAT_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetCatOfProjectsThatAResHasDocPermission TO MSProjectServerRole
GO



/* Query #66031 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllPCProjects
AS
select P.WPROJ_ID, P.WPROJ_DEFAULT_WPROJ_ID, P.PROJ_NAME, R.RES_NAME from MSP_WEB_PROJECTS P, MSP_WEB_RESOURCES R where P.WPROJ_IS_NONWORKING=0 and P.WPROJ_TYPE<>3 and P.WRES_ID=R.WRES_ID order by P.WPROJ_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllPCProjects TO MSProjectServerRole
GO



/* Query #66032 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetSecFeatureByID
   @p0 INT
AS
select WSEC_FEA_ACT_ID from MSP_WEB_SECURITY_FEATURES_ACTIONS where WSEC_FEA_ACT_ID=@p0 and WSEC_FEA_ACT_PARENT=0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetSecFeatureByID TO MSProjectServerRole
GO



/* Query #66033 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_EnableDisableFeatureByID
   @p0 TINYINT,
   @p1 TINYINT,
   @p2 INT
AS
update MSP_WEB_SECURITY_ORG_PERMISSIONS set WSEC_ALLOW=@p0, WSEC_DENY=@p1 where WSEC_FEA_ACT_ID in ( select WSEC_FEA_ACT_ID from MSP_WEB_SECURITY_FEATURES_ACTIONS where WSEC_FEA_ACT_ID=@p2 or WSEC_FEA_ACT_PARENT=@p2 )

-- Special handling for Enterprise Feature (1000). 
-- Also Enable/Disable "Create Administrative Projects"(207), "View Enterprise Resource View" (504), "View Vision"(505), "View Models"(506)
if (@p2 = 1000)
begin
  update MSP_WEB_SECURITY_ORG_PERMISSIONS set WSEC_ALLOW=@p0, WSEC_DENY=@p1 where WSEC_FEA_ACT_ID=207
  update MSP_WEB_SECURITY_ORG_PERMISSIONS set WSEC_ALLOW=@p0, WSEC_DENY=@p1 where WSEC_FEA_ACT_ID=504
  update MSP_WEB_SECURITY_ORG_PERMISSIONS set WSEC_ALLOW=@p0, WSEC_DENY=@p1 where WSEC_FEA_ACT_ID=505
  update MSP_WEB_SECURITY_ORG_PERMISSIONS set WSEC_ALLOW=@p0, WSEC_DENY=@p1 where WSEC_FEA_ACT_ID=506
end

RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_EnableDisableFeatureByID TO MSProjectServerRole
GO



/* Query #67016 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetGroupByGrpGUID
   @p0 UNIQUEIDENTIFIER
AS
select WSEC_GRP_NAME, WSEC_GRP_DESC, WSEC_GRP_DASHBOARD_URL, WSEC_GRP_AD_GROUP from MSP_WEB_SECURITY_GROUPS where WSEC_GRP_GUID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetGroupByGrpGUID TO MSProjectServerRole
GO



/* Query #67017 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetGroupAllCategories
   @p0 UNIQUEIDENTIFIER
AS
  select CAT.WSEC_CAT_ID, CAT.WSEC_CAT_NAME 
    from MSP_WEB_SECURITY_CATEGORIES CAT, 
         MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR 
   where SCR.WSEC_SP_GUID=@p0 
     and SCR.WSEC_CAT_ID<>0 
     and SCR.WSEC_CAT_ID=CAT.WSEC_CAT_ID 
   order by CAT.WSEC_CAT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetGroupAllCategories TO MSProjectServerRole
GO



/* Query #67018 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetAllUsersForGroup
   @p0 UNIQUEIDENTIFIER
AS
  select R.WRES_ID, R.WRES_GUID, R.RES_NAME 
    from MSP_WEB_RESOURCES R, 
         MSP_WEB_SECURITY_GROUP_MEMBERS GM 
   where GM.WSEC_GRP_GUID=@p0 
     and GM.WRES_GUID=R.WRES_GUID
     and WRES_CAN_LOGIN = 1
     and WRES_COUNT_LICENSE = 1
   order by R.RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetAllUsersForGroup TO MSProjectServerRole
GO



/* Query #67021 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetGroupByGrpID
   @p0 INT
AS
select WSEC_GRP_GUID, WSEC_GRP_NAME, WSEC_GRP_DESC, WSEC_GRP_DASHBOARD_URL, WSEC_GRP_AD_GROUP from MSP_WEB_SECURITY_GROUPS where WSEC_GRP_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetGroupByGrpID TO MSProjectServerRole
GO


/* Query #67101 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteGroupMember
   @p0 UNIQUEIDENTIFIER,
   @p1 UNIQUEIDENTIFIER
AS
delete from MSP_WEB_SECURITY_GROUP_MEMBERS where WSEC_GRP_GUID=@p0 and WRES_GUID=@p1 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteGroupMember TO MSProjectServerRole
GO



/* Query #67102 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetSpCatRelation
   @p0 UNIQUEIDENTIFIER,
   @p1 INT
AS
select * from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_SP_GUID=@p0 and WSEC_CAT_ID=@p1 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetSpCatRelation TO MSProjectServerRole
GO



/* Query #67104 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteGroupMemberByResource
   @p0 UNIQUEIDENTIFIER
AS
delete from MSP_WEB_SECURITY_GROUP_MEMBERS where WRES_GUID=@p0 and WSEC_GRP_GUID<>WRES_GUID RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteGroupMemberByResource TO MSProjectServerRole
GO



/* Query #67105 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteGroupMemberByGroup
   @p0 UNIQUEIDENTIFIER
AS
delete from MSP_WEB_SECURITY_GROUP_MEMBERS where WSEC_GRP_GUID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteGroupMemberByGroup TO MSProjectServerRole
GO



/* Query #67106 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteSpCatRelationsBySP
   @p0 UNIQUEIDENTIFIER,
   @p1 INT
AS
BEGIN
   if (@p1 = -1)
     delete from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_SP_GUID=@p0
   else if (@p1 = 0)
     delete from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_SP_GUID=@p0 and WSEC_CAT_ID=0
   else if (@p1 = 0)
     delete from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_SP_GUID=@p0 and WSEC_CAT_ID<>0
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteSpCatRelationsBySP TO MSProjectServerRole
GO



/* Query #67107 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteSpCatPermissionsBySP
   @p0 UNIQUEIDENTIFIER,
   @p1 INT
AS
BEGIN
   if (@p1 = -1)
     delete from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS where WSEC_REL_ID in (select WSEC_REL_ID from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_SP_GUID=@p0)
   else if (@p1 = 0)
     delete from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS where WSEC_REL_ID in (select WSEC_REL_ID from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_SP_GUID=@p0 and WSEC_CAT_ID=0)
   else if (@p1 = 1)
     delete from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS where WSEC_REL_ID in (select WSEC_REL_ID from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_SP_GUID=@p0 and WSEC_CAT_ID<>0)
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteSpCatPermissionsBySP TO MSProjectServerRole
GO



/* Query #67108 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetCategoryByCatID
   @p0 INT
AS
select * from MSP_WEB_SECURITY_CATEGORIES where WSEC_CAT_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetCategoryByCatID TO MSProjectServerRole
GO



/* Query #67109 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteCategoryByCatID
   @p0 INT
AS
delete from MSP_WEB_SECURITY_CATEGORIES where WSEC_CAT_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteCategoryByCatID TO MSProjectServerRole
GO



/* Query #67110 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteCategoryRulesByCatID
   @p0 INT
AS
delete from MSP_WEB_SECURITY_CATEGORY_RULES where WSEC_CAT_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteCategoryRulesByCatID TO MSProjectServerRole
GO



/* Query #67111 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteCategoryObjectsByCatID
   @p0 INT
AS
delete from MSP_WEB_SECURITY_CATEGORY_OBJECTS where WSEC_CAT_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteCategoryObjectsByCatID TO MSProjectServerRole
GO



/* Query #67112 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteSpCatRelationsByCatID
   @p0 INT
AS
delete from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_CAT_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteSpCatRelationsByCatID TO MSProjectServerRole
GO



/* Query #67113 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteSpCatPermissionsByCatID
   @p0 INT
AS
delete from MSP_WEB_SECURITY_SP_CAT_PERMISSIONS where WSEC_REL_ID in (select WSEC_REL_ID from MSP_WEB_SECURITY_SP_CAT_RELATIONS where WSEC_CAT_ID=@p0) RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteSpCatPermissionsByCatID TO MSProjectServerRole
GO



/* Query #67116 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetEOrDGroupByGroupName
   @p0 NVARCHAR(100)
AS
select * from MSP_WEB_SECURITY_GROUPS where WSEC_GRP_NAME=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetEOrDGroupByGroupName TO MSProjectServerRole
GO


/* Query #67117 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_InsertGroupMemberByResIDs
   @p0 UNIQUEIDENTIFIER,
   @p1 NTEXT
AS
BEGIN
   insert into MSP_WEB_SECURITY_GROUP_MEMBERS (WSEC_GRP_GUID, WRES_GUID)
   (
     select @p0, WRES_GUID
       from MSP_WEB_RESOURCES
      where WRES_ID in (select TokenVal from dbo.MSP_WEB_FN_ConvertListToTable(@p1))
   )
RETURN(0)
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_InsertGroupMemberByResIDs TO MSProjectServerRole
GO


/* Query #67119 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteGroupMembersByGrpGUID
   @p0 UNIQUEIDENTIFIER
AS
delete from MSP_WEB_SECURITY_GROUP_MEMBERS where WSEC_GRP_GUID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteGroupMembersByGrpGUID TO MSProjectServerRole
GO



/* Query #67120 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteGroupByGrpGUID
   @p0 UNIQUEIDENTIFIER
AS
delete from MSP_WEB_SECURITY_GROUPS where WSEC_GRP_GUID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteGroupByGrpGUID TO MSProjectServerRole
GO



/* Query #67121 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetEOrDGroupByGrpGUID
   @p0 UNIQUEIDENTIFIER
AS
select WSEC_GRP_GUID, WSEC_GRP_NAME, WSEC_GRP_DESC, WSEC_GRP_DASHBOARD_URL, WSEC_GRP_AD_GROUP, WSEC_GRP_AD_LOG from MSP_WEB_SECURITY_GROUPS where WSEC_GRP_GUID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetEOrDGroupByGrpGUID TO MSProjectServerRole
GO



/* Query #67122 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteCustomOrgMenuBar
   @p0 INT
AS
Delete From MSP_WEB_SECURITY_MENUS Where WSEC_MENU_ID>10000 and ((WSEC_MENU_ID=@p0 and WSEC_MENU_PARENT_ID=-1) or (WSEC_MENU_PARENT_ID=@p0)) RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteCustomOrgMenuBar TO MSProjectServerRole
GO



/* Query #67123 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_ModifyOrgMenuBar
   @p0 SMALLINT,
   @p1 INT
AS
Update MSP_WEB_SECURITY_MENUS Set WSEC_MENU_SEQ=@p0 Where WSEC_MENU_ID=@p1 and WSEC_MENU_PARENT_ID=-1 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_ModifyOrgMenuBar TO MSProjectServerRole
GO



/* Query #67124 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetMenuInfoByMenuID
   @p0 INT
AS
Select * From MSP_WEB_SECURITY_MENUS Where WSEC_MENU_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetMenuInfoByMenuID TO MSProjectServerRole
GO



/* Query #67125 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteCustomMenuByMenuIDAndParentID
   @p0 INT,
   @p1 INT
AS
Delete From MSP_WEB_SECURITY_MENUS Where WSEC_MENU_ID=@p0 and WSEC_MENU_PARENT_ID=@p1 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteCustomMenuByMenuIDAndParentID TO MSProjectServerRole
GO



/* Query #67126 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetSubMenusByMenuID
   @p0 INT
AS
Select * From MSP_WEB_SECURITY_MENUS Where WSEC_MENU_PARENT_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetSubMenusByMenuID TO MSProjectServerRole
GO



/* Query #67127 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetNextMenuSeq
   @p0 INT
AS
Select Max(WSEC_MENU_SEQ)+1 as NextSeq From MSP_WEB_SECURITY_MENUS Where WSEC_MENU_PARENT_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetNextMenuSeq TO MSProjectServerRole
GO



/* Query #67128 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeletePageForMenuByMenuID
   @p0 INT
AS
Delete From MSP_WEB_SECURITY_PAGES where WSEC_PAGE_ID in (select WSEC_MENU_PAGE_ID from MSP_WEB_SECURITY_MENUS where WSEC_MENU_ID=@p0 and WSEC_MENU_PAGE_ID > 0) RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeletePageForMenuByMenuID TO MSProjectServerRole
GO



/* Query #67129 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteMenuByMenuID
   @p0 INT
AS
Delete From MSP_WEB_SECURITY_MENUS where WSEC_MENU_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteMenuByMenuID TO MSProjectServerRole
GO



/* Query #67130 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetSubMenusForMenuByMenuID
   @p0 INT
AS
Select * From MSP_WEB_SECURITY_MENUS Where WSEC_MENU_PARENT_ID=@p0 Order By WSEC_MENU_SEQ RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetSubMenusForMenuByMenuID TO MSProjectServerRole
GO



/* Query #67132 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetPageInfoByPageID
   @p0 INT
AS
Select * From MSP_WEB_SECURITY_PAGES where WSEC_PAGE_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetPageInfoByPageID TO MSProjectServerRole
GO



/* Query #67133 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_GetTemplateInfoByTmplID
   @p0 INT
AS
select * from MSP_WEB_SECURITY_TEMPLATES where WSEC_TMPL_ID=@p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_GetTemplateInfoByTmplID TO MSProjectServerRole
GO



/* Query #67135 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteTemplatePermissionsByTmplID
   @p0 INT
AS
delete from MSP_WEB_SECURITY_TEMPLATE_PERMISSIONS where WSEC_TMPL_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteTemplatePermissionsByTmplID TO MSProjectServerRole
GO



/* Query #67136 */
CREATE PROCEDURE dbo.MSP_WEB_SP_SEC_DeleteTemplateByTmplID
   @p0 INT
AS
delete from MSP_WEB_SECURITY_TEMPLATES where WSEC_TMPL_ID=@p0 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_SEC_DeleteTemplateByTmplID TO MSProjectServerRole
GO



/* Query #70003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNumberOfPendingCalendarTransForMgr
   @p0 INT
AS
select COUNT(MSP_WEB_NONWORKING.WNONWORK_ID) AS TNumTrans from MSP_WEB_NONWORKING,MSP_WEB_MESSAGES,MSP_WEB_MESSAGES_NONWORKING,MSP_WEB_RESOURCES,MSP_WEB_RESOURCES R2 where R2.WRES_ID = @p0 and MSP_WEB_MESSAGES.WRES_ID_RECEIVER=R2.WRES_ID and  MSP_WEB_MESSAGES.WMSG_ID=MSP_WEB_MESSAGES_NONWORKING.WMSG_ID and MSP_WEB_MESSAGES_NONWORKING.WNONWORK_ID=MSP_WEB_NONWORKING.WNONWORK_ID and MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_MESSAGES.WRES_ID_SENDER RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNumberOfPendingCalendarTransForMgr TO MSProjectServerRole
GO



/* Query #80000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllResRegFields
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, MAS.AS_VALUE, VF.WFIELD_NAME_OLEDB, VF.WFIELD_TEXTCONV_TYPE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and VF.WTABLE_ID=3 and VF.WFIELD_IS_ENTRES_FIELD=1)
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.ATTRIB_FIELD_ID<>205521540 and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   Order By CV.CONV_STRING
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllResRegFields TO MSProjectServerRole
GO



/* Query #80001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAllResRegFieldsForNewViews
   @p0 INT
AS
BEGIN
  declare @ent_global_proj_id int
  select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

  Select VF.WFIELD_ID, CV.CONV_STRING, MAS.AS_VALUE
    From MSP_WEB_VIEW_FIELDS VF INNER JOIN MSP_WEB_CONVERSIONS CV on (VF.WFIELD_NAME_CONV_VALUE=CV.CONV_VALUE and CV.LANG_ID=@p0 and VF.WTABLE_ID=3 and VF.WFIELD_IS_ENTRES_FIELD=1)
         LEFT JOIN MSP_FIELD_ATTRIBUTES  MFA on (VF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.ATTRIB_FIELD_ID<>205521540 and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206)
         LEFT JOIN MSP_ATTRIBUTE_STRINGS MAS on (MAS.PROJ_ID=@ent_global_proj_id and MFA.AS_ID=MAS.AS_ID)
   where not VF.WFIELD_ID in (3092,3184)
   Order By CV.CONV_STRING
RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAllResRegFieldsForNewViews TO MSProjectServerRole
GO



/* Query #80002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ResRegViewAllFieldsList
   @p0 INT,
   @p1 INT
AS
BEGIN
declare @ent_global_proj_id int
select @ent_global_proj_id=PROJ_ID from MSP_PROJECTS WITH (INDEX=I_MSP_PROJECTS_PROJ_TYPE) where PROJ_TYPE=2

select WVF.WFIELD_ID,CONV_STRING,AS_VALUE,WFIELD_NAME_OLEDB,WFIELD_TEXTCONV_TYPE,WVRF.WVIEW_FIELD_WIDTH,WVRF.WVIEW_FIELD_AUTOSIZE, 
	   CASE WHEN EXISTS (SELECT * FROM MSP_FIELD_ATTRIBUTES MFA2 WHERE MFA2.ATTRIB_ID=211 AND MFA2.ATTRIB_FIELD_ID= WVF.WFIELD_ID)THEN 0 ELSE NULL END AS INDICATOR_VAL
  from MSP_WEB_VIEW_REPORTS_FIELDS WVRF inner join MSP_WEB_VIEW_FIELDS WVF on WVRF.WFIELD_ID=WVF.WFIELD_ID and WVRF.WVIEW_ID=@p1 and WVF.WTABLE_ID=3 and WVF.WFIELD_IS_ENTRES_FIELD=1
       inner join MSP_WEB_CONVERSIONS WC on WVF.WFIELD_NAME_CONV_VALUE=WC.CONV_VALUE and LANG_ID=@p0
       left join MSP_FIELD_ATTRIBUTES MFA on WVF.WFIELD_ID=MFA.ATTRIB_FIELD_ID and MFA.PROJ_ID=@ent_global_proj_id and ATTRIB_ID=206
       left join MSP_ATTRIBUTE_STRINGS MAS on MFA.AS_ID=MAS.AS_ID and MAS.PROJ_ID=@ent_global_proj_id
 order by WVRF.WVIEW_FIELD_ORDER
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ResRegViewAllFieldsList TO MSProjectServerRole
GO


/* Query #80003 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResourceCenterViewRSBasedOnFieldList
   @res_id        INT,
   @field_list    nvarchar(2000),  -- 2000 : MAX_PORTFOLIO_FIELDS
   @filter_string nvarchar(1000),  -- filter string
   @fFilterByRBS  INT
AS
BEGIN
  declare @sql_query  nvarchar(4000)

  set @sql_query = N'
  SELECT ^0 
   FROM MSP_VIEW_RES_STD             A 
        INNER JOIN MSP_VIEW_RES_CF   B  on A.ResourceUniqueID=B.CF_ResourceUniqueID 
        INNER JOIN MSP_VIEW_RES_ENT  C  on A.ResourceUniqueID=C.ENT_ResourceUniqueID 
        INNER JOIN MSP_WEB_RESOURCES D  on A.ResourceUniqueID=D.RES_EUID 
        INNER JOIN MSP_RESOURCES     R  on D.RES_EUID=R.RES_UID 
        INNER JOIN MSP_PROJECTS      P  on R.PROJ_ID=P.PROJ_ID 
        INNER JOIN MSP_WEB_FN_SEC_GetAllResourcesResCanViewByViewID(^1,1014,-1) SEC  on D.WRES_ID=SEC.WRES_ID '

  if (@fFilterByRBS <> 0)
  begin
    set @sql_query = @sql_query + N'INNER JOIN MSP_WEB_FN_SEC_GetResourcesManagedByResID(^1,0,-1) RBS  on D.WRES_ID=RBS.WRES_ID '
  end

  set @sql_query = @sql_query + N'WHERE P.PROJ_TYPE=3 ^2'

  -- insert the parameters into sql statement
  set @sql_query = REPLACE(@sql_query, N'^0', @field_list)
  set @sql_query = REPLACE(@sql_query, N'^1', @res_id)
  set @sql_query = REPLACE(@sql_query, N'^2', @filter_string)

  -- execute the query
  exec sp_executesql @sql_query

RETURN
END
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResourceCenterViewRSBasedOnFieldList TO MSProjectServerRole
GO


/* Query #80004 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetResourceCenterViewInfoForViewID
   @p0 INT
AS
   Select * 
     From MSP_WEB_VIEW_REPORTS 
    WHERE WVIEW_ID=@p0 
      and WVIEW_TYPE=3
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetResourceCenterViewInfoForViewID TO MSProjectServerRole
GO


/* Query #80005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_ResourceCenterViewMainFieldList
   @p0 INT
AS
   select A.WFIELD_ID,WFIELD_NAME_OLEDB,  
		  CASE WHEN EXISTS (SELECT * FROM MSP_FIELD_ATTRIBUTES MFA INNER JOIN MSP_PROJECTS MP ON(MFA.PROJ_ID = MP.PROJ_ID) where PROJ_TYPE=2 AND ATTRIB_ID=211 AND ATTRIB_FIELD_ID= A.WFIELD_ID)THEN 0 ELSE NULL END AS INDICATOR_VAL
     from MSP_WEB_VIEW_FIELDS A,
          MSP_WEB_VIEW_REPORTS_FIELDS B 
    where B.WVIEW_ID=@p0
      and A.WFIELD_ID=B.WFIELD_ID 
      and A.WTABLE_ID=3 
      and A.WFIELD_IS_ENTRES_FIELD=1 
    order by B.WVIEW_FIELD_ORDER 
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_ResourceCenterViewMainFieldList TO MSProjectServerRole
GO


/* Query #90000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetDefaultDataSpace
   @p0 INT
AS
select * from MSP_WEB_SECURITY_PAGES where WSEC_PAGE_ID = @p0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetDefaultDataSpace TO MSProjectServerRole
GO



/* Query #90001 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetAdminSettings
AS
select * from MSP_WEB_ADMIN RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetAdminSettings TO MSProjectServerRole
GO



/* Query #90002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_UpdateAdminTimePeriodSettings
   @p0 INT,
   @p1 TINYINT,
   @p2 TINYINT,
   @p3 TINYINT,
   @p4 INT,
   @p5 TINYINT,
   @p6 TINYINT,
   @p7 TINYINT,
   @p8 TINYINT,
   @p9 TINYINT,
   @p10 TINYINT,
   @p11 TINYINT,
   @p12 DECIMAL(25,6),
   @p13 INT,
   @p14 TINYINT,
   @p15 TINYINT
AS

Update MSP_WEB_ADMIN set
   WADMIN_DEFAULT_TRACKING_METHOD    = @p0,
   WADMIN_IS_TRACKING_METHOD_LOCKED  = @p1,
   WADMIN_TIMESHEET_SPAN             = @p2,
   WADMIN_WEEKLY_TIMESHEET_NUM_WEEKS = @p3,
   WADMIN_WEEK_STARTS_ON             = @p4,
   WADMIN_MONTHLY_REPORTS_PER_MONTH  = @p5,
   WADMIN_MONTHLY_1PRD_1ST_START     = @p6,
   WADMIN_MONTHLY_2PRDS_1ST_START    = @p7,
   WADMIN_MONTHLY_2PRDS_1ST_END      = @p8,
   WADMIN_MONTHLY_3PRDS_1ST_START    = @p9,
   WADMIN_MONTHLY_3PRDS_1ST_END      = @p10,
   WADMIN_MONTHLY_3PRDS_2ND_END      = @p11,
   WADMIN_MAX_HOUR_PER_DAY           = @p12,
   WADMIN_LOOKAHEAD                  = @p13,
   WADMIN_TIMEPERIOD_GRANULARITY     = @p14,
   WADMIN_PROTECT_ACTUALS            = @p15

-- if Protect Actuals, we will disable 'Connect to Project Server using Project 2002 and Older' permission for PS.
IF @p15 <> 0
   UPDATE MSP_WEB_SECURITY_ORG_PERMISSIONS set WSEC_ALLOW=0, WSEC_DENY=1 where WSEC_FEA_ACT_ID=108

RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_UpdateAdminTimePeriodSettings TO MSProjectServerRole
GO



/* Query #90012 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_RenameFavoriteViews
   @p0 INT,
   @p1 INT,
   @p2 NVARCHAR(100)
AS
Update MSP_WEB_VIEW_FAVORITES set WVIEW_FAV_NAME = (@p2) Where WVIEW_FAV_ID = @p0 and WRES_ID = @p1 RETURN(0)
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_RenameFavoriteViews TO MSProjectServerRole
GO



/* Query #370002 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetCalendarTransRecords
   @p0 INT
AS
select MSP_WEB_NONWORKING.WNONWORK_ID WASSN_ID, MSP_WEB_MESSAGES_NONWORKING.WMSGNONWORK_ID, MSP_WEB_MESSAGES_NONWORKING.WMSG_ID, MSP_WEB_RESOURCES.RES_NAME, MSP_WEB_NONWORKING.* 
from MSP_WEB_NONWORKING,MSP_WEB_MESSAGES,MSP_WEB_MESSAGES_NONWORKING,MSP_WEB_RESOURCES 
where MSP_WEB_MESSAGES.WRES_ID_RECEIVER=@p0 
  and MSP_WEB_MESSAGES.WMSG_ID=MSP_WEB_MESSAGES_NONWORKING.WMSG_ID 
  and MSP_WEB_MESSAGES_NONWORKING.WNONWORK_ID=MSP_WEB_NONWORKING.WNONWORK_ID 
  and MSP_WEB_RESOURCES.WRES_ID=MSP_WEB_MESSAGES.WRES_ID_SENDER 
order by MSP_WEB_MESSAGES.WMSG_TIME RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetCalendarTransRecords TO MSProjectServerRole
GO



/* Query #30045 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetUseNTLogonFlagForResID
   @p0 INT
AS
Select WRES_USE_NT_LOGON From MSP_WEB_RESOURCES Where WRES_ID=(@p0) and WRES_IS_ENABLED<>0 RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetUseNTLogonFlagForResID TO MSProjectServerRole
GO



/* Query #35500 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetOutlineCodeMasksForViews
   @p1 INT
AS
select WWFI.CUSTFIELD_INFO_ID as TFieldName, AS_VALUE as TMask,CASE WHEN MFA2.ATTRIB_VALUE IS NOT NULL THEN 1 ELSE 0 END as TRequiredField 
from MSP_ATTRIBUTE_STRINGS MAS INNER JOIN MSP_FIELD_ATTRIBUTES MFA ON (MAS.AS_ID=MFA.AS_ID and MAS.PROJ_ID=MFA.PROJ_ID)
INNER JOIN MSP_WEB_VIEW_REPORTS_FIELDS WVRF ON ATTRIB_FIELD_ID=WVRF.WFIELD_ID
INNER JOIN MSP_PROJECTS MP ON MAS.PROJ_ID=MP.PROJ_ID
INNER JOIN MSP_WEB_WORKGROUP_FIELDS_INFO WWFI ON ATTRIB_FIELD_ID=WWFI.FIELD_ID 
LEFT  JOIN MSP_FIELD_ATTRIBUTES MFA2 ON MFA2.PROJ_ID = MP.PROJ_ID AND MFA2.ATTRIB_FIELD_ID=WWFI.FIELD_ID AND MFA2.ATTRIB_ID = 213
where WVIEW_ID=@p1 and MP.PROJ_TYPE=2 and MFA.ATTRIB_ID=200 
union
select WWFI.CUSTFIELD_INFO_ID as TFieldName, AS_VALUE as TMask ,CASE WHEN MFA3.ATTRIB_VALUE IS NOT NULL THEN 1 ELSE 0 END as TRequiredField  
from MSP_FIELD_ATTRIBUTES MFA inner join MSP_FIELD_ATTRIBUTES MFA2 on MFA2.ATTRIB_VALUE=MFA.ATTRIB_FIELD_ID
INNER JOIN MSP_ATTRIBUTE_STRINGS MAS ON (MAS.AS_ID=MFA.AS_ID and MAS.PROJ_ID=MFA.PROJ_ID)
INNER JOIN MSP_WEB_VIEW_REPORTS_FIELDS WVRF ON MFA2.ATTRIB_FIELD_ID=WVRF.WFIELD_ID
INNER JOIN MSP_PROJECTS MP ON MAS.PROJ_ID=MP.PROJ_ID
INNER JOIN MSP_WEB_WORKGROUP_FIELDS_INFO WWFI ON MFA2.ATTRIB_FIELD_ID=WWFI.FIELD_ID 
LEFT  JOIN MSP_FIELD_ATTRIBUTES MFA3 ON MFA3.PROJ_ID = MP.PROJ_ID AND MFA3.ATTRIB_FIELD_ID=WWFI.FIELD_ID AND MFA3.ATTRIB_ID = 213
where WVIEW_ID=@p1 and MP.PROJ_TYPE=2 and MFA.ATTRIB_ID=200 and MFA2.ATTRIB_ID=212
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetOutlineCodeMasksForViews TO MSProjectServerRole
GO



/* Query #235600 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_GetEditCustomMenuInfo
   @p0 INT
AS
select (case when WSEC_MENU_NAME_ID is null then WSEC_MENU_CUSTOM_NAME else CONV_STRING end) as CONV_STRING,
       WSEC_MENU_IS_TOP_LEVEL as TASK_IS_SUMMARY,
       WSEC_MENU_ID as TASK_UID,
       WSEC_MENU_PARENT_ID as TASK_UID_SUMMARY,
       WPROJ_ID=1,
       WSEC_MENU_SEQ, WSEC_MENU_CUSTOM_NAME,WSEC_MENU_IS_CUSTOM,WSEC_PAGE_CUSTOM_URL,WSEC_MENU_CUSTOM_DESC 
  from (MSP_WEB_SECURITY_MENUS WSM LEFT JOIN MSP_WEB_SECURITY_PAGES WSP ON WSM.WSEC_MENU_PAGE_ID=WSP.WSEC_PAGE_ID) 
       LEFT JOIN MSP_WEB_CONVERSIONS WC ON WSM.WSEC_MENU_NAME_ID=WC.CONV_VALUE and LANG_ID=@p0

RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_GetEditCustomMenuInfo TO MSProjectServerRole
GO



/* Query #245000 */
CREATE PROCEDURE dbo.MSP_WEB_SP_BUS_GetGroupSchemeSettings
   @p0 INT
AS
Select MSP_WEB_GROUP_SETTINGS.*,CONV_STRING as WGROUP_STYLE_NAME,WGROUP_SCHEME_NAME from MSP_WEB_GROUP_SETTINGS,MSP_WEB_GROUP_STYLES,MSP_WEB_GROUP_SCHEMES,MSP_WEB_CONVERSIONS Where LANG_ID=@p0 and WGROUP_STYLE_CONV_VALUE=CONV_VALUE and MSP_WEB_GROUP_SETTINGS.WGROUP_STYLE_ID=MSP_WEB_GROUP_STYLES.WGROUP_STYLE_ID and MSP_WEB_GROUP_SETTINGS.WGROUP_SCHEME_ID=MSP_WEB_GROUP_SCHEMES.WGROUP_SCHEME_ID Order By MSP_WEB_GROUP_SETTINGS.WGROUP_STYLE_ID RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_BUS_GetGroupSchemeSettings TO MSProjectServerRole
GO



/* Query #265008 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetAllGroups
AS
select WSEC_GRP_ID, WSEC_GRP_NAME, WSEC_GRP_DESC, WSEC_GRP_DASHBOARD_URL, WSEC_GRP_AD_GROUP, WSEC_GRP_AD_LOG from MSP_WEB_SECURITY_GROUPS order by WSEC_GRP_NAME RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetAllGroups TO MSProjectServerRole
GO



/* Query #265009 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetGroupMembersByGroupID
   @p0 INT
AS
select R.RES_NAME 
  from MSP_WEB_SECURITY_GROUPS G
       INNER JOIN MSP_WEB_SECURITY_GROUP_MEMBERS GM ON (G.WSEC_GRP_ID=@p0 and G.WSEC_GRP_GUID=GM.WSEC_GRP_GUID)
       INNER JOIN MSP_WEB_RESOURCES R ON (GM.WRES_GUID=R.WRES_GUID and R.WRES_CAN_LOGIN=1 and R.WRES_COUNT_LICENSE=1)
 order by R.RES_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetGroupMembersByGroupID TO MSProjectServerRole
GO



/* Query #265010 */
CREATE PROCEDURE dbo.MSP_WEB_SP_ADM_SecGetGroupCategoriesByGroupID
   @p0 INT
AS
select CAT.WSEC_CAT_NAME 
  from MSP_WEB_SECURITY_GROUPS G,
       MSP_WEB_SECURITY_SP_CAT_RELATIONS SCR, 
       MSP_WEB_SECURITY_CATEGORIES CAT 
 where G.WSEC_GRP_ID=@p0
   and G.WSEC_GRP_GUID = SCR.WSEC_SP_GUID
   and SCR.WSEC_CAT_ID=CAT.WSEC_CAT_ID
 order by CAT.WSEC_CAT_NAME
RETURN
GO

GRANT EXECUTE ON dbo.MSP_WEB_SP_ADM_SecGetGroupCategoriesByGroupID TO MSProjectServerRole
GO



/* Query #265011 */
