Abd Al-Kareem Attiya
Abd Al-Kareem Attiya

Reputation: 53

Why We Can't Select Data From Temporary Table into another Temporary Table

My Code Like

SELECT col1, Col2, Col3, Col4 
INTO #Temp1
FROM Emplyees;

and second Query :

SELECT Col1,Sum(Col2)
INTO #Temp2
FROM #temp1

The Second Query Don't Work and gave me Error as Empty or Wrong Aliases column

untill you Select * From #Temp1 . This make me ASK why sql accepted * and not for some column Selected .

Thanks For all.

Upvotes: 1

Views: 262

Answers (2)

Kell
Kell

Reputation: 3327

Well the error is a bit misleading. I would expect it to moan about the lack of a group by clause and the lack of a real name for the second column. Try this:

SELECT Col1, Sum(Col2) AS SumCol
INTO #Temp2
FROM #temp1 
GROUP BY Col1

Upvotes: 1

Rodion
Rodion

Reputation: 886

SELECT Col1, Sum(Col2) as SumofCol2
INTO #Temp2
FROM #temp1
GROUP BY Col1

Upvotes: 2

Related Questions