I have created a temp table and would like to email the results I am getting the following error.
Query execution failed: Msg 208, Level 16, State 1, Server PRODYCHDBX3\X3V7, Line 1 Invalid object name '#WODups'.
After the temp table is created I ran the following code.
DECLARE @recordcount INT
SELECT @recordcount = ISNULL(COUNT(*),0)
FROM #WODups
IF (@recordcount > 0)
BEGIN
SELECT * FROM #WODups
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQL Mail',
@recipients = '[email protected];[email protected]',
@query = 'SELECT FROM #WODups',
@subject = 'Duplicate Work Order Production Tracking',
--@attach_query_result_as_file = 1,
@body =0;
DROP TABLE #WODups
Why am I getting this error, and how may I resolve it?