Azii Mahmood
Azii Mahmood

Reputation: 15

#TempTable in stored procedure

I'm just inserting some values into #TempTable (which is not defined) by using SELECT INTO from a function within a stored procedure. But can see the #TempTable being created in temporary tables drop down list in the database.

Moreover is there any difference between already defines #TempTable with some attributes and Just using INSERT INTO #TempTable without defining it. Same query when I run outside of the stored procedure it creates a #tempTable.

ALTER PROEDURE SpBorBySec 
    (@sec NVARCHAR(30))
AS
BEGIN
    SELECT * 
    FROM FnFoBoSec(@sec)

    SELECT 
        BorrowerID, Borrowerfname, SUM(fine) AS Total_fine, 
        COUNT(BorrowerID) AS Total_Loan 
    INTO
        #BorrowerSummary   
    FROM
        FnFoBoSec(@sec) 
    GROUP BY
        BorrowerID, BorrowerFName

    SELECT * FROM #BorrowerSummary
END

Upvotes: 0

Views: 52

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89091

Same query when i run outside of Stored Procedure it creates a #tempTable.

The temp table is created in the stored procedure, but temp tables created in a stored procedure are automatically dropped at the end of the stored procedure.

Upvotes: 1

Related Questions