June 30, 2022 at 6:33 pm
Hi all,
I have a very short query that contains an effective date but not expiration date. I would like to populate a expiration date set to 1 day before the next row's effective date. Here is query and results. For example, on part 100-121-0000, Revision A2; I'd like the Expiration Date to be 08-09-2009 based on one day before the Effective Date of Revision B, whose Effective Date is 08/10/2009. Hope that makes sense. Thanks in advance.
June 30, 2022 at 7:13 pm
You will probably want to use LEAD windowing function. -- e.g.,
DATEADD(day,-1,LEAD(EffectiveDate ) OVER (PARTITION BY PartNum ORDER BY EffectiveDate))
-- Assumes RevisionNum is correctly determined in order based on EffectiveDate, so we can order only by EffectiveDate
June 30, 2022 at 7:57 pm
If you'd like a tested coded answer, please read and heed the first link in my signature line below.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply