Hi All
Ive got all my tables sorted now for a work database project but am struggling a little with the query side.
Im calculating holiday entitlement for employees based on numerous factors and would like some help combining queries
Today is my first day ever writing SQL so please bear with me. I initially started writing the combined query but couldnt get anywhere, so i broke it down and have got the result that i require from multiple queries strung together, however du to the amount im going to require id rather get these merged into one if possible. The single queries are:
*Selects the latest employee contract and the amount of months duration
SELECT DATEDIFF("m",StartDate,NOW()) AS ContractLength
FROM CONTRACT
WHERE ContractID = (SELECT max(ContractID)
FROM CONTRACT);
then we have
*Selects Additional Days Service holiday entitlement based on the contract length
SELECT IIF (ContractLength BETWEEN 0 AND 11.99,'0',IIF(ContractLength BETWEEN 12 AND 23.99,'1',IIF(ContractLength BETWEEN 24 AND 35.99,'2',IIF(ContractLength BETWEEN 36 AND 47.99,'3',IIF(ContractLength BETWEEN 48 AND 59.99,'4','5'))))) AS AdditionalDaysHolidays
FROM LatestContractQuery;
then we have
*Total Holiday Entitlement
SELECT (AdditionalDaysHoliday + 20) AS HolidayEntitlement
FROM AdditionalDaysServiceQuery;
Now ive been playing for hours but am struggling and just cannot get it to work. Ive tried UNION, Nested SELECT, but just keep getting to :banghead:
As the result of each query does not output to a table the main stumbling block i come accross is FROM errors
Please help
Ive got all my tables sorted now for a work database project but am struggling a little with the query side.
Im calculating holiday entitlement for employees based on numerous factors and would like some help combining queries
Today is my first day ever writing SQL so please bear with me. I initially started writing the combined query but couldnt get anywhere, so i broke it down and have got the result that i require from multiple queries strung together, however du to the amount im going to require id rather get these merged into one if possible. The single queries are:
*Selects the latest employee contract and the amount of months duration
SELECT DATEDIFF("m",StartDate,NOW()) AS ContractLength
FROM CONTRACT
WHERE ContractID = (SELECT max(ContractID)
FROM CONTRACT);
then we have
*Selects Additional Days Service holiday entitlement based on the contract length
SELECT IIF (ContractLength BETWEEN 0 AND 11.99,'0',IIF(ContractLength BETWEEN 12 AND 23.99,'1',IIF(ContractLength BETWEEN 24 AND 35.99,'2',IIF(ContractLength BETWEEN 36 AND 47.99,'3',IIF(ContractLength BETWEEN 48 AND 59.99,'4','5'))))) AS AdditionalDaysHolidays
FROM LatestContractQuery;
then we have
*Total Holiday Entitlement
SELECT (AdditionalDaysHoliday + 20) AS HolidayEntitlement
FROM AdditionalDaysServiceQuery;
Now ive been playing for hours but am struggling and just cannot get it to work. Ive tried UNION, Nested SELECT, but just keep getting to :banghead:
As the result of each query does not output to a table the main stumbling block i come accross is FROM errors
Please help