Hi guys,
I am trying to run a query that calculates when employees become eligible for supplemental vacation. This occcurs once the employee has reached 5, 10, 15, etc years of service. I got the query running great, it shows the correct dates, (5, 10, etc years after the HireDate) but I just found out that they don't want to know the exact anniversary date. People become entitled to their vacation January 1st of the year of their anniversary date. So, for example, say their 5th anniversary is May 11, 2009, their eligibility date should then be Jan. 1, 2009. The query I have right now shows May 11, 2009. How can I get it to show Jan. 1 of the anniversary year? Here's my query so far: - SELECT [Main].[LastName] & ", " & [Main].[FirstName] AS Name, Employee.ID, EmplOrganization.DepartmentCode, Department.Desc, EmplOrganization.DivisionCode, Division.Desc, Job.Title, EmplStatus.StatusCode, Employee.HireDate, EmplDays.TotalDaysEmployed, EmplDays.Years, EmplDays.Months, EmplDays.Days, IIf(DateAdd("m",60,[HireDate])>Now(),DateAdd("m",60,[HireDate]), IIf(DateAdd("m",120,[HireDate])>Now(),DateAdd("m",120,[HireDate]), IIf(DateAdd("m",180,[HireDate])>Now(),DateAdd("m",180,[HireDate]), IIf(DateAdd("m",240,[HireDate])>Now(),DateAdd("m",240,[HireDate]), IIf(DateAdd("m",300,[HireDate])>Now(),DateAdd("m",300,[HireDate]), IIf(DateAdd("m",360,[HireDate])>Now(),DateAdd("m",360,[HireDate]), IIf(DateAdd("m",420,[HireDate])>Now(),DateAdd("m",420,[HireDate]), IIf(DateAdd("m",480,[HireDate])>Now(),DateAdd("m",480,[HireDate]),"")))))))) AS SupplementalEligibility, Category.Code, CategoryReason.Desc
-
FROM Main RIGHT JOIN (Job RIGHT JOIN (Department RIGHT JOIN (((((Employee LEFT JOIN EmplDays ON Employee.ID = EmplDays.EmployeeID) LEFT JOIN (CategoryReason RIGHT JOIN (Category RIGHT JOIN EmplCategory ON Category.Code = EmplCategory.CategoryCode) ON CategoryReason.Code = EmplCategory.CategoryReasonCode) ON Employee.ID = EmplCategory.EmployeeID) LEFT JOIN EmplJob ON Employee.ID = EmplJob.EmployeeID) LEFT JOIN (Division RIGHT JOIN EmplOrganization ON Division.Code = EmplOrganization.DivisionCode) ON Employee.ID = EmplOrganization.EmployeeID) LEFT JOIN EmplStatus ON Employee.ID = EmplStatus.EmployeeID) ON Department.Code = EmplOrganization.DepartmentCode) ON Job.Code = EmplJob.JobCode) ON Main.ID = Employee.MainID
-
WHERE (((EmplStatus.StatusCode)="A" Or (EmplStatus.StatusCode)="LOA") AND ((CategoryReason.Desc)="Permanent") AND ((EmplCategory.Active)=True) AND ((EmplJob.Active)=True) AND ((EmplOrganization.Active)=True) AND ((EmplStatus.Active)=True));
Also, in my iif statement in the query, I get an #Error if none of the conditions evaluate to true. My "" doesn't seem to work because I'm dealing with dates. How can I get an empty string or something like NA to show up instead of #Error? (i.e. After 40 years of services there is no more supplemental vacation)
3 2149 FishVal 2,653
Recognized Expert Specialist
Hi, colleague.
So basically you need to generate date Jan-1-<Some year>.
DataSerial with Year function will be useful here.
Something like. -
DateSerial (Year(dteDateReturned),1,1)
-
BTW I suggest you to use Switch function which works exactly like iif's nested through <false> section. Despite Switch function doesn't have <Default/False> section you can easily simulate it with one of the following -
Switch(expr1, value1, expr2, value2, ...., True, valueDefault)
-
Nz(Switch(expr1, value1, expr2, value2, ....), valueDefault)
-
Towards your 2nd question.
Queries return variant type to a field. There is no problem to get strings and dates simultaneously in one column. The reason for #Error is definitely not a types conflict.
Regards,
Fish
DataSerial with Year function will be useful here....
Thanks Fish, the DateSerial worked perfectly.
BTW I suggest you to use Switch function which works exactly like iif's nested through <false> section.....
What would be the advantage of using the Switch function over the nested iif's? I've never used the switch function before.
Towards your 2nd question.
Queries return variant type to a field. There is no problem to get strings and dates simultaneously in one column. The reason for #Error is definitely not a types conflict.
Hmm...Not sure why I'm getting this #Error. As I said, if I try "" it comes up, I tried "NA" and that doesn't work. I tried Now() and that DID work, so that's why I originally thought it didn't like the empty string. I'll keep looking at that part.
FYI, using the switch statement: - Switch(DateAdd("m",60,[HireDate])>Now(),DateAdd("m",60,[HireDate]), DateAdd("m",120,[HireDate])>Now(),DateAdd("m",120,[HireDate]), DateAdd("m",180,[HireDate])>Now(),DateAdd("m",180,[HireDate]), DateAdd("m",240,[HireDate])>Now(),DateAdd("m",240,[HireDate]), DateAdd("m",300,[HireDate])>Now(),DateAdd("m",300,[HireDate]), DateAdd("m",360,[HireDate])>Now(),DateAdd("m",360,[HireDate]), DateAdd("m",420,[HireDate])>Now(),DateAdd("m",420,[HireDate]), DateAdd("m",480,[HireDate])>Now(),DateAdd("m",480,[HireDate]),True,"") AS SupplementaryEligibility
works great and leaves a blank rather than #Error for those with more than 40 years service to the company.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jlm |
last post by:
I have a form which feeds table (TblEmpLeave) of Employee Leave Time
(time taken off for Administrative, Annual, Sick, Compensation leave).
I have EmpID, LeaveDate, LeaveType, LeaveHours fields on this form.
Any employee can have multiple entries in the table (key fields are
EmpID and LeaveID) for multiple dates (John Doe can take 3 days annual
leave, then take 3 days sick leave in any given month.
I have a BeginningBalance of hours that...
|
by: spidrw |
last post by:
I have a system that lets users input service events (much like
appointments at a Dr.'s office). Oftentimes a particular person will
have 30 or 31 appointments in a month, as all events are consecutive.
All that is logged is days of service, not duration or anything. For
our contractual reporting purposes, I used to be able to simply input
30 (or 31) days of service if someone visited every day for a month,
but now I must create...
|
by: MLH |
last post by:
Anybody's solution would be appreciated. Pls,
do not pause to write anything for this. I'm not
looking for that kind of a handout. I have an idea
about how to do it, but I wanted to see if anyone
has already done it and is proud of their achieve-
ment and willing to share it.
The courts order public sales of property in judgments
in my county. They require the auctioneers to schedule
future dates and advertise them (Sundays not...
|
by: hlam |
last post by:
Help - Calculating the total of a column in a data grid --
when data grid is part of Master-Detail set-up
I have setup a Master-Detail form using Visual
Studio.Net. A ListBox is the (Master) and contains a list
of dates. The data grid (Details portion) contains the
details for a selected date (namely, a list of work codes
and hours spent).
I am trying to total the number of hours in the datagrid
|
by: clintonb |
last post by:
I'm looking for a way to calculate the number of days between two
dates using standard C++ functions.
Would it be as simple as just using the difftime() function and then
dividing that result by the number of seconds in a day?
- Clint
| |
by: rshivaraman |
last post by:
Hi :
I have a TableA with around 10 columns with varchar and numeric
datatypes
It has 500 million records and its size is 999999999 KB. i believe it
is kb
i got this data after running sp_spaceused on it. The index_size was
also pretty big in 6 digits.
On looking at the tableA
|
by: ncsthbell |
last post by:
I am having problems getting the end date to calculate correctly.
I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates for each 'month' in the quarter, hence, I want to calculate the begin & end of the month dates for April, May & June 2003 :
so my starting point is:
firstMonthBegin = vcBegMM & "/" & vcBegDD & "/" & vcBegYY
firstMonthEnd = vcEndMM &...
|
by: =?Utf-8?B?QWw=?= |
last post by:
I am working in vb2005. how can I calculate business days (not including
holidays and weekends) between 2 dates? thanks
Al
|
by: John |
last post by:
Hi
How can I calculate days from the two dates entered in date time picker
fields on winform by a user?
Thanks
Regards
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |