-1

IF EXISTS ( SELECT * FROM #temp_person ) BEGIN PRINT 'Temporary Table Does Not Exist'; END

I am trying to write in SQL to check if a temporary table exists, if so output the contents of the table, and if not print that the table does not exist. This current query returns an invalid object name of the table.

1 Answers1

1
IF OBJECT_ID('tempdb..#temp_person') IS NOT NULL
BEGIN
    SELECT *
    FROM #temp_person
END
ELSE
BEGIN
    PRINT 'Temporary Table Does Not Exist'
END
Detsawm
  • 69
  • 5