I have an internal Department that will be switching account numbers in the future. I am trying to build a stored procedure to return only one of two rows based upon an effective date.
Here's the data makeup
|ID | EffectiveDate | AccountNum |
|-- | ------------- | ---------- |
| 1 | 2021-01-01 | 350000 |
| 2 | 2021-09-01 | 950000 |
I know this returns all the data
SELECT Id, EffectiveDate, AccountNum
FROM Account
This returns only the first row and never the 2nd:
SELECT Id, EffectiveDate, DeptNum
FROM Account
WHERE EffectiveDate <= GETDATE()
How would I dynamically return only 1 row based upon today's date?
So if the Effective date is less than today's date get row one. If the Effective Date is equal to or greater than todays date get row two.
select top 1 ... order by EffectiveDate desc?