が欠落しているようGROUP BY
で、構文が少しずれています。これを試して:
SELECT
p1.pa_value as SDay,
p2.pa_value as SMonth,
p3.pa_value as SYear,
p4.pa_value as EDay,
p5.pa_value as EMonth,
p6.pa_value as EYear,
SUBSTRING(p7.PA_NAME,11, len(p7.PA_NAME)) as _index_,
p8.pa_value as _status_,
p9.pa_value as approved_CHECK_status,
p10.pa_value as expense_type_CHECK,
p11.pa_value as congress_name,
p12.pa_value as _Initiator_,
p13.pa_value as planned_budget,
p14.pa_value as actual_budget,
p15.pa_value as congressNumHCP,
p16.pa_value as congressNumMSD,
p17.pa_value as RequestNumber,
test.timestampmin
FROM WP_WorkflowProcess p
LEFT JOIN PA_Parameter p1 on p1.PA_WP_ID=p.wp_id AND p1.PA_NAME = 'Event_Day_From'
LEFT JOIN PA_Parameter p2 on p2.PA_WP_ID=p.wp_id AND p2.PA_NAME = 'Event_Month_From'
LEFT JOIN PA_Parameter p3 on p3.PA_WP_ID=p.wp_id AND p3.PA_NAME = 'Event_Year_From'
LEFT JOIN PA_Parameter p4 on p4.PA_WP_ID=p.wp_id AND p4.PA_NAME = 'Event_Day_To'
LEFT JOIN PA_Parameter p5 on p5.PA_WP_ID=p.wp_id AND p5.PA_NAME = 'Event_Month_To'
LEFT JOIN PA_Parameter p6 on p6.PA_WP_ID=p.wp_id AND p6.PA_NAME = 'Event_Year_To'
LEFT JOIN PA_Parameter p7 on p7.PA_WP_ID=p.wp_ID
AND ((p7.PA_NAME like 'reqExpense_' AND CAST( p7.PA_wp_id as varchar(15) ) like CAST( p.wp_id as varchar(5) ) COLLATE DATABASE_DEFAULT )
OR (p7.PA_NAME like 'reqExpense__' AND CAST( p7.PA_wp_id as varchar(15) ) like CAST( p.wp_id as varchar(5) ) COLLATE DATABASE_DEFAULT) )
LEFT JOIN PA_Parameter p8 on p8.PA_WP_ID=p.wp_id AND p8.PA_NAME = 'EventStatus'
LEFT JOIN PA_Parameter p9 on p9.PA_WP_ID=p.wp_id AND p9.PA_NAME = 'MAapproval'
LEFT JOIN PA_Parameter p10 on p10.PA_WP_ID=p.wp_id AND p10.PA_NAME = 'reqExpense'+ SUBSTRING(p7.PA_NAME,11, len(p7.PA_NAME))
LEFT JOIN PA_Parameter p11 on p11.PA_WP_ID=p.wp_id AND p11.PA_NAME = 'EventNameReal'
LEFT JOIN PA_Parameter p12 on p12.PA_WP_ID=p.wp_id AND p12.PA_NAME = 'Requisitioner'
LEFT JOIN PA_Parameter p13 on p13.PA_WP_ID=p.wp_id AND p13.PA_NAME = 'Preliminary_BudgetText'
LEFT JOIN PA_Parameter p14 on p14.PA_WP_ID=p.wp_id AND p14.PA_NAME = 'Final_BudgetText'
LEFT JOIN PA_Parameter p15 on p15.PA_WP_ID=p.wp_id AND p15.PA_NAME = 'congressNumberHCP'+SUBSTRING(p7.PA_NAME,11, len(p7.PA_NAME))
LEFT JOIN PA_Parameter p16 on p16.PA_WP_ID=p.wp_id AND p16.PA_NAME = 'congressNumberMSD'+SUBSTRING(p7.PA_NAME,11, len(p7.PA_NAME))
LEFT JOIN PA_Parameter p17 on p17.PA_WP_ID=p.wp_id AND p17.PA_NAME = 'RequestNumber'
INNER JOIN
(
SELECT min(TA_Timestamp) as timestampmin, ta_wp_id as ta_wp_id
FROM ta_tasks
GROUP BY ta_wp_id
) as test
ON test.ta_wp_id = p17.PA_WP_ID
WHERE p.wp_type='EventManagementNew'