Hi @Pelican
Yes, you could wrap your code into a stored procedure and then create a SQL Server Agent job that executes this stored procedure on a monthly schedule.
Considering that there is a date filter in the where condition, you might need to modify it. Cause you did not clarify the detailed logic, so here is the code depending on my guess that you execute this code on the first day of each month to query data from the previous month.
CREATE PROCEDURE [dbo].[MonthlyAutoTask]
AS
BEGIN
select
......
from tblST T INNER JOIN tblIC L ON T.LOCTID=L.LOCTID
where INVDTE BETWEEN DATEADD(DAY, 1, EOMONTH(GETDATE(), -2)) and EOMONTH(GETDATE(), -1)
order by STATE
END
Then you could create a SQL Server agent job to run this SP.
You may refer to this guide: Create A SQL Job to Run a Stored Procedure.
Best regards,
Cosmog
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".