I am needing to automate a report to go out on a monthly basis that uses End of Month tables. Currently, I have to go in every month and adding in the new monthly table within the subquery in order for the data to be accurate. Is there a way to union an additional query if a condition is TRUE. The condition in question is the date. The 01/2021 table doesn't exist until 02/01/2021, so I don't want to read in the two lines until then because SQL fails when it reads in a non existing table. Code Below:
Select * FROM
(Select '12.2020' as [Starting Point], [CustomerID],[Days]
from dbo.EOM_Table_202012
UNION ALL
---Insert IF statement and jump over lines if date is not greater than 01/31/2021
Select '1.2021' as [Starting Point],[CustomerID],[Days]
from dbo.EOM_Table_202101) a
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…