I have written query by combining two tables and result looks like below mentioned
Result Set
recipient_email | recipient_name | accrual_deadline | CCA |
---|---|---|---|
siva@gmail.com | siva | jun 24 | reddy@gmail.com |
siva@gmail.com | siva | jun 24 | sa@gmail.com |
mohan@gmail.com | mohan | jun 24 | ma@gmail.com |
mohan@gmail.com | mohan | jun 24 | run@gmail.com |
Query:
SELECT te.email AS recipient_email
,te.employee_name AS recipient_name
,(
SELECT CONVERT(VARCHAR, DATEADD(d, - 3, MAX(TRANSACTION_DATE)), 107)
FROM [POT].[vw_Calendar]
WHERE CURRENT_FISCAL_YEAR_FLAG = 'Y'
AND CURRENT_FISCAL_QUARTER_FLAG = 'Y'
) AS accrual_deadline
,'GR' AS emp_type
,te1.email AS CostCenterAnalyst FROM [POT].[vw_POT_Open_PO] op
LEFT JOIN POT.vw_Employee te ON te.Employee_Number = op.Goods_Recipient_Emp_ID
AND te.flag_Status = 'A'
JOIN POT.vw_Employee te1 ON te1.Employee_Number = op.pocostcenteranlystid
LEFT JOIN [POT].[tbl_POT_Open_PO_Accrual_Reminder_History] opair ON DATEPART(month, GETDATE()) + DATEPART(year, GETDATE()) = DATEPART(month, [Mail_Sent_On]) + DATEPART(year, [Mail_Sent_On])
AND [Recipient_Email] = te.email
AND opair.Flag_Active = 1
AND [Reminder_Type] = 'Accrual_Input'
WHERE te.email IS NOT NULL
AND opair.Recipient_Email IS NULL
AND te.Email IN (
'siva@amat.com'
,'mohan@amat.com'
) GROUP BY te.email
,te.employee_name
,te1.email
I have to group the recipient_email and result should display like below
recipient_email | recipient_name | accrual_deadline | CCA |
---|---|---|---|
siva@gmail.com | siva | jun 24 | reddy@gmail.com; sa@gmail.com |
mohan@gmail.com | mohan | jun 24 | ma@gmail.com; run@gmail.com |