select distinct pa1.project_attrvalue Brand,
p1.project_manager PrgManager,
pa2.project_attrvalue GBU,
p1.Project_Name PrjName,
p.u_email,
wda.DOCUMENT_NAME DocumentName,
wda.DocVersion_Counter versionNumber,
(u.U_FirstName+' '+u.U_LastName) Approver,
DATENAME(weekday, CONVERT(varchar(50),wda.APPROVALINFO_DUEDATE,107))+','+
DATENAME(month, CONVERT(varchar(50),wda.APPROVALINFO_DUEDATE,107))+
right(CONVERT(varchar(50),wda.APPROVALINFO_DUEDATE,107),9) duedate
from webcenter.WCREPORTS_PROJECTSQ p1 join webcenter.WCREPORTS_PROJECT_ATTRQ pa1 on p1.project_id=pa1.PROJECT_ID
join webcenter.WCREPORTS_PROJECT_ATTRQ pa2 on p1.project_id=pa2.PROJECT_ID
join webcenter.WCREPORTS_DOCAPPROVALQ wda on p1.project_id=wda.PROJECT_ID
join webcenter.DOCVERSION_APPROVERSQ da on da.dvai_docver_id=wda.docversion_id
join webcenter.USER_MEMBERSQ u on u.u_id=da.SA_USER_ID
join webcenter.ProjectsQ p on (p.P_Manager_Id=p1.Project_ManagerId and p.p_id=p1.project_id)
where pa2.PROJECT_ATTRNAME='ALL - GBU' and
pa1.PROJECT_ATTRNAME=(pa2.project_attrvalue+' - Brand') and
p1.project_statusname != 'Discontinued' and
p1.project_name not like 'TEST%' and wda.DocVersion_ApprovalStatus='Pending' and
da.dvai_approvalstate=wda.approvalinfo_approvalstate
p1.project_manager PrgManager,
pa2.project_attrvalue GBU,
p1.Project_Name PrjName,
p.u_email,
wda.DOCUMENT_NAME DocumentName,
wda.DocVersion_Counter versionNumber,
(u.U_FirstName+' '+u.U_LastName) Approver,
DATENAME(weekday, CONVERT(varchar(50),wda.APPROVALINFO_DUEDATE,107))+','+
DATENAME(month, CONVERT(varchar(50),wda.APPROVALINFO_DUEDATE,107))+
right(CONVERT(varchar(50),wda.APPROVALINFO_DUEDATE,107),9) duedate
from webcenter.WCREPORTS_PROJECTSQ p1 join webcenter.WCREPORTS_PROJECT_ATTRQ pa1 on p1.project_id=pa1.PROJECT_ID
join webcenter.WCREPORTS_PROJECT_ATTRQ pa2 on p1.project_id=pa2.PROJECT_ID
join webcenter.WCREPORTS_DOCAPPROVALQ wda on p1.project_id=wda.PROJECT_ID
join webcenter.DOCVERSION_APPROVERSQ da on da.dvai_docver_id=wda.docversion_id
join webcenter.USER_MEMBERSQ u on u.u_id=da.SA_USER_ID
join webcenter.ProjectsQ p on (p.P_Manager_Id=p1.Project_ManagerId and p.p_id=p1.project_id)
where pa2.PROJECT_ATTRNAME='ALL - GBU' and
pa1.PROJECT_ATTRNAME=(pa2.project_attrvalue+' - Brand') and
p1.project_statusname != 'Discontinued' and
p1.project_name not like 'TEST%' and wda.DocVersion_ApprovalStatus='Pending' and
da.dvai_approvalstate=wda.approvalinfo_approvalstate