SQLTeam.com | Weblogs | Forums

Query condition


#1

Hello SQL Expert,

Below is the data I have and what I am trying to do is to to make the column "Task Date" fill with the date ONLY IF the column "Task Code" value is WRK otherwise is the value in "Task Date" is NULL.

Here is my basic query:

SELECT Employee_Initial, EmployeeID, Employee_Fname, Task_Code, Task_Date
FROM EmployeeTBL

Here is the current ouput:

and here the result set I want:

Column Task_Code not necessary has to be in the output but the reason I display it just that you can see the background what I am trying to do. The fields that I am interested are: Employee_Initial, EmployeeID, Employee_Fname, and Task_Date

Anyone can help me how do I update my query?

Thanks guys


#2

How about:

SELECT Employee_Initial, EmployeeID, Employee_Fname, Task_Code, 
    CASE WHEN Task_Code = 'WRK' THEN Task_Date ELSE NULL END AS Task_Date
FROM EmployeeTBL

#3

Thank you djj55


#4

You are welcome