Re: Need Help With an Update Script



That sounds pretty complicated. <<

It is a lot easier than what you are trying to do. Why do you keep
thinking about procedural instead of declarative code, materialized
data instead of virtual? This is SQL, not COBOL. Build a base table
and make sure that it follows your business rules

CREATE TABLE Patients
( ..
admit_date DATETIME NOT NULL,
discharge_date DATETIME NOT NULL,
CHECK (discharge_date = DATEADD(DAY, 3, admit_date)),
,..);

Now just show this to the users:

CREATE VIEW CurrentPatients (., admit_date, discharge_date, ..)
AS
SELECT .., admit_date,
CASE WHEN discharge_date <= CURRENT_TIMESTAMP
THEN discharge_date ELSE NULL END AS discharge_date,
...
FROM Patients;

No scripts, triggers, proprietary transaction syntax, host language
procedures, etc.

.