Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use CASE logic in a Access 2003 query? 1

Status
Not open for further replies.

yehong

Programmer
Sep 22, 2003
291
US
I have this simple query but its not working. Keep getting error message that operator is missing.

"Select Employee.ID, (Case When (Employee.hire_Date IS NUll) Then '12/31/2020' Else Employee.hire_date End) AS Hire_Date
from employee;
 
Unless of course your backend is in SQL server, forget Transact SQL... You'll have to use Jet functions to accomplish the same thing. IIF function and Isnull is waht you need. Isnull tells you whether or not a value is null in JET. The equivalent funtion to the Transact Isnull in jet is NZ (null to zero). And Jet uses the hash (#) as the delimiter for dates...

Select Employee.ID, IIF(isnull(Employee.hire_Date) = yes, #12/31/2020#, Employee.hire_date End) AS Hire_Date
from employee;

 
Why not simply this ?
"SELECT ID, Nz(hire_Date,#2020-12-31#) AS Hire_Date FROM employee"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top