FreeriderUK
Well-known member
Previously I have been using MSACCESS databases, but have now changed to SQL.
I was able to use the following to calculate a Due_Date based on the Last_Done date:
How can the same thing be acheived in SQL?
The best I can come up with is:
The problem is, JET allowed the IIF to use a calculated field, but SQL EXPRESS doesn't seem to like it.
I know 'CalculatedDueDate' is a string - if I try using CalculatedDueDate, I get an 'invalid column name' error.
I was able to use the following to calculate a Due_Date based on the Last_Done date:
VB.NET:
SELECT
Manual_Due, Last_Done,
Last_Done + Freq * 7 AS Calculated_Due,
CVDate(IIf(IsNull(Manual_Due), Calculated_Due, Manual_Due)) AS Due_Date
FROM Customers
How can the same thing be acheived in SQL?
The best I can come up with is:
VB.NET:
SELECT Frequency, Period, LastDone,
CASE Period
WHEN '1' THEN dateadd(dd, Frequency, LastDone)
WHEN '2' THEN dateadd(wk, Frequency, LastDone)
WHEN '3' THEN dateadd(mm, Frequency, LastDone)
WHEN '4' THEN dateadd(yy, Frequency, LastDone)
END AS CalculatedDueDate, ManualDueDate,
ISNULL(ManualDueDate, 'CalculatedDueDate') AS ScheduledDueDate
FROM Customers
The problem is, JET allowed the IIF to use a calculated field, but SQL EXPRESS doesn't seem to like it.
I know 'CalculatedDueDate' is a string - if I try using CalculatedDueDate, I get an 'invalid column name' error.