DECLARE @SQL NVARCHAR(MAX);
SET @SQL = N'
CREATE TABLE #TempTableDynamicSQLIn
(
ID INT NOT NULL,
SomeString NVARCHAR(50) NULL
)
INSERT INTO #TempTableDynamicSQLIn
( ID, SomeString)
VALUES
( 1, ''Some String'')
SELECT * FROM #TempTableDynamicSQLIn
';
EXECUTE sp_executesql @SQL;
EXEC @SQL;
Error message:
Msg 203, Level 16, State 2, Line 16
The name '
CREATE TABLE #TempTableDynamicSQLIn
(
ID INT NOT NULL,
SomeString NVARCHAR(50) NULL
)
INSERT INTO #TempTableDynamicSQLIn
( ID, SomeString)
VALUES
( 1, 'Some String')
SELECT * FROM #TempTableDynamicSQLIn
' is not a valid identifier.
Solution:
EXECUTE sp_executesql @SQL;
Temp tables created in EXEC can't use temp table caching mechanism.
No comments:
Post a Comment