Saturday, 16 June 2018

MSSQL - Fix Error - Incorrect syntax near the keyword 'Exec'.

Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'Exec'.

Watch this example on YouTube



I am trying to insert records from results of stored procedure

 to fix it replace

select * into #TemplTable
from Exec [SelectProducts]
select * FROM #TemplTable

with


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

CREATE TABLE #TemplTable (ProductID int, ProdName varchar(max))
Insert Into #TemplTable
Exec [SelectProducts]

select * FROM #TemplTable

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







No comments:

Post a Comment