I have an existing query that outputs current data, and I would like to insert it into a Temp table, but am having some issues doing so. Would anybody have some insight on h
SELECT * INTO #TempTable
FROM SampleTable
WHERE...
SELECT * FROM #TempTable
DROP TABLE #TempTable
Fastest way to do this is using "SELECT INTO" command e.g.
SELECT * INTO #TempTableName
FROM....
This will create a new table, you don't have to create it in advance.
Try this:
SELECT *
INTO #Temp
FROM
(select * from tblorders where busidate ='2016-11-24' and locationID=12
) as X
Please use alias with x so it will not failed the script and result.
You can do that like this:
INSERT INTO myTable (colum1, column2)
SELECT column1, column2 FROM OtherTable;
Just make sure the columns are matching, both in number as in datatype.
SELECT *
INTO #Temp
FROM
(SELECT
Received,
Total,
Answer,
(CASE WHEN application LIKE '%STUFF%' THEN 'MORESTUFF' END) AS application
FROM
FirstTable
WHERE
Recieved = 1 AND
application = 'MORESTUFF'
GROUP BY
CASE WHEN application LIKE '%STUFF%' THEN 'MORESTUFF' END) data
WHERE
application LIKE
isNull(
'%MORESTUFF%',
'%')
SQL Server R2 2008 needs the AS
clause as follows:
SELECT *
INTO #temp
FROM (
SELECT col1, col2
FROM table1
) AS x
The query failed without the AS x
at the end.
It's also needed when using SS2016, had to add as t
to the end.
Select * into #result from (SELECT * FROM #temp where [id] = @id) as t //<-- as t