SQLTeam.com | Weblogs | Forums

Insert Records in Temp Table for running another Query


#1

Hi

I want to Insert Records in Temp Table for running another Query in same Stored Procedure

Thanks


#2

You could create Temp table as
CREATE TABLE #TMP(YourCOL TYPE)
or
DECLARE @TMP AS TABLE(YourCOL TYPE)

And can insert records in these temp table before utilizing again in the same store procedure.


#3

You can use "SELECT INTO" command

SELECT * INTO #TempTableName
FROM....

This will create a new table.


#4

Hi

Incorrect syntax near Group. I need all the columns in Temp Table also.

Select * InTo #_Total From(
SELECT a.empid,b.empname,b_empmarks
FROM empmaster a
LEFT OUTER JOIN empdetail b
on a.empid = b.empid
WHERE a.empid =@empid)
GROUP BY a.empid
ORDER BY a.empid

Thanks