SQL Server : cannot access temporary tables
The server does not allow modification of any table in a function. Use a table variable instead.
declare @temp table (RowNum int, JOBDateTime DateTime, JOBEvent int)insert into @temp SELECT ROW_NUMBER() OVER(ORDER BY JOBID) AS ROWNUM, JOBDateTime, JOBEvent FROM JOBsActivityData where JOBID = @USERID and JOBDateTime >= @JOBStartDATE...
when using table variables, you do not need to drop them.
Instead of using a Temp table, use a table variable, that should solve your problem. See this similar question Cannot access temporary tables from within a function