Forum Discussion
Gcsingh90
Jul 15, 2023Copper Contributor
Calculating Main Current Task column by concatenating 2 task names based on multiple conditions
Hello, I am trying to solve the problem if someone can help that would be appreciated. I am beginning my journey with SQL. Desired Output - Main Current Task Column Task ID column is in ASCEN...
Francisco_nitt
Jul 15, 2023Copper Contributor
Based on the provided description and sample data, it seems that you are looking for a logic to calculate the "Main Current Task" column based on certain conditions. Here's a possible approach to achieve that:
Create a temporary table or view with the necessary columns: Job ID, Language, Task Type, Parent_Find, Tsk Id, Tsk Status, and Project_Deliverable_Not_Deliverable.
Use the following SQL query to calculate the "Main Current Task" column:
SELECT
t1.`Job ID`,
t1.`Language`,
t1.`Task Type`,
t1.`Parent_Find`,
t1.`Tsk Id`,
t1.`Tsk Status`,
CONCAT(t1.`Task Type`,
CASE
WHEN t1.`Tsk Status` = 'Delivered' AND t1.`Project_Deliverable_Not_Deliverable` = 'Deliverable' THEN
(SELECT CONCAT(' + ', t2.`Task Type`)
FROM your_table_name t2
WHERE t2.`Language` = t1.`Language`
AND t2.`Parent_Find` = t1.`Parent_Find`
AND t2.`Tsk Status` = 'Delivered'
AND t2.`Project_Deliverable_Not_Deliverable` = 'Deliverable'
AND t2.`Tsk Id` > t1.`Tsk Id`
ORDER BY t2.`Tsk Id` ASC
LIMIT 1)
ELSE ''
END
) AS `Main Current Task`,
t1.`Project_Deliverable_Not_Deliverable`
FROM your_table_name t1
Replace your_table_name with the actual name of the table or view you created in step 1.
This query uses a subquery to find the next delivered task with deliverable project status within the same language group and parent. It concatenates the current task with the found task using the CONCAT function.
Note: Make sure to adjust the column names and table/view names in the query based on your actual schema.
Hope this will help you.