2

I am writing a Store Procedure in SQL Server 2012. I have a temporary table defined like so:

  DECLARE @CURRENT_RET_WEEK_PTIMEIDS TABLE ( PTIMEID INT )

I am also using EXECUTE to write a dynamic SQL query. Is there any way I can join this table onto the above temporary table?

Devart
  • 119,203
  • 23
  • 166
  • 186
Lock
  • 5,422
  • 14
  • 66
  • 113

1 Answers1

5

Try to use local temp-table -

IF OBJECT_ID ('tempdb.dbo.#temp') IS NOT NULL
   DROP TABLE #temp

CREATE TABLE #temp (ID INT)
INSERT INTO #temp (ID)
VALUES (1),(2)

DECLARE @SQL NVARCHAR(MAX)
SELECT @SQL = 'SELECT * FROM #temp'

EXEC sys.sp_executesql @SQL
Devart
  • 119,203
  • 23
  • 166
  • 186