I now have an intermediate view in SQL Server, and a final view, as follows:
Intermediate view:
SELECT
....
ElapsedDays = DATEDIFF(d, ri.DateReceived, GETDATE()),
.....
FROM
RegionalInventory AS ri
Final view:
SELECT
....
PenaltyBucket = COALESCE(CASE WHEN inv.ElapsedDays <= 30 THEN 'Not Late' END,
CASE WHEN inv.ElapsedDays > 30 THEN 'Late' END)
....
FROM
Inventory AS inv
I am wondering if there's a way for me to combine both views into one, but I am not sure how to declare a variable to hold the value of ElapsedDays, and then use it to set the value for the ElapsedDays column and to do the logical test, to both create the PenaltyBucket column and fill it with the right value.