I am trying to turn my sql results into a temp table but it keeps on returning the following error:
Expecting As or Id or quoted-ID.
I know the sql result is correct but when I add SELECT * INTO #newtable FROM, the sql query doesn't work. What is wrong?
SELECT *
INTO #newtable
FROM
(
SELECT
Url,Id
FROM Blob
WHERE
Id IN
(
SELECT
BlobId
FROM
XrefBlobProjectMeeting
)
AND Extension NOT IN ('xlsx','xls','avi','jpg','mp4','wmv','png')
AND (RefContentTypeId IN (11,13,14,35))
)
INSERT INTO ... SELECTandSELECT...INTObehave very differently.INSERT INTO dbo.MyTable SELECT 1 AS i;The statement will fail, however,SELECT 1 AS i INTO dbo.MyTable;will work fine. ConverselyCREATE TABLE MyTable (i int); INSERT INTO dbo.MyTable SELECT 1 AS i;will work fine, butCREATE TABLE MyTable (i int); SELECT 1 AS i INTO dbo.MyTable;will not.SELECT..INTOsyntax will create the object as part of the statement. if the object already exists, the statement fails. forINSERT INTO...SELECTthe complete opposite is true; the object must already exist, and if it does not, the statement will fail.