There is already an object named '#temp' in the database


I am getting error after executing the query .
Please Note:- This error occurred after Upgrading metabase from x.37.x , 0.38, 0.39 version till 0.40.8 (IN sequence)
The same query is working in .37.0.1 version kindly help us to resolve this issue
For reference I am attaching the screenshot of error message.