I am currently updating an Excel file from SQL monthly. My query starts from a With() for CTE which includes date range last month (like between '2024-06-01' and '2024-06-30'), it runs like less than 10 minutes if the dates are hardcoded, or like forever if I declare the variables using formulas to get the dynamic date:
@StartDate as date = datefromparts( Year( DATEADD(month, -1, getdate())), Month(DATEADD(month, -1, getdate())), 1)
@EndDate as date = eomonth(@startdate)
which never works on SQL takes 2-3 hours and tell me Timeout or lost connection ...
I wish i could make an automation for it by creating a flow, get the startdate and enddate in the flow and use them in the sql query:
both dates are string since no date type in power automate.
I am using the same sql query and insert the 2 variables in the cte. it's not really difficult just with some "case when", joins and one date range:
but it takes more than 3 hours to run the flow, my first try failed with a 502 bad gateway -- i could get data from sql but takes a long time, the info should not be wrong; or if the db name or table name not correct i don't think it should take 3.5 hours to know.
I am not using desktop since my license doesn't support running in the backend and wondering if cloud flows could help with this. -- i only want it runs monthly and append to an Excel in sharepoint as a quick resource, no more manually inputs.
And, is it possible to use power automate to build the code like hardcoded, or it works just like variables?
Thank you!

Report
All responses (
Answers (