AnsweredAssumed Answered

How can i insert from temp table?

Question asked by Techapat on Oct 25, 2018
Latest reply on Oct 25, 2018 by Eugene Lee

Code :

-- VARIABLES

DECLARE @TSQL varchar(200)

DECLARE @VAL float

-- GET DATA

SELECT @TSQL = 'SELECT * FROM [TEST].[dbo].[tested]'

-- DEFINE TABLE & INSERT TEMP TABLE

DECLARE @t TABLE (Tag varchar(100),Times varchar(100),VAL float)

INSERT @t

EXEC(@TSQL)

-- INSERT OTHER TABLE

SELECT @TSQL = 'SELECT * FROM OPENQUERY([PI], ''INSERT INTO piarchive..picomp2 (tag,time,value) SELECT * FROM @t'')'

EXEC (@TSQL)

 

i got error msg "OLE DB provider "PIOLEDB" for linked server "PI" returned message "[SQL Parser] [Line 1] Syntax error near '@'."."

How can i fix it?

Outcomes