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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating the enddate

Status
Not open for further replies.

BasSchouten

IS-IT--Management
Jul 31, 2001
33
NL
I'v got two tables SAL and DVB
DVB contains info on a workingcontract
SAL contains information historic salaries on those workingcontracts. The tables consists of the following columns:
Code:
DVB:
DVBDVBIDN    (identity)
DVBDVBDTB    (startdate of contract)
DVBDVBDTE    (enddate of contract, 9999-12-31 if no enddate)

SAL:
SALSALIDN    (identity)
SALDVBIDN    (foreign key into DVB)
SALSALSAL    (salary)
SALSALDTB    (Startdate of this salary)

I want to create a view of salaries of a certain contract and include the enddate of that salary. The enddate of salary X should be calculated as follows:
If there exists a salary Y of the same contract that starts after salary X, then the enddate of salary X is the startdate of Salary Y - 1 day.
If salary X is the latest salary, then the enddate of the salary is the enddate of the contract.

I'v created the separate coding for the two options:
Option 1:
Code:
SELECT MIN(SALSALDTB)-1 FROM PDPSAL01 SAL2
WHERE SAL1.SALDVBIDN = SAL2.SALDVBIDN
  AND SAL2.SALDVBDTB > SAL1.SALSALDTB

Option 2:
Code:
SELECT DVBDVBDTE FROM PDPDVB01
WHERE SAL1.SALDVBIDN = DVBDVBIDN

How do i incorporate these two options as one field in a view definition? Bas Schouten
System Development & Webdesign
CBIS BV Holland
logo.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top