• Despite MSSQL 2000, MSSQL 2005 allows to insert SP output into a particular subset of columns independently if it is a table variable or a temporary table. I found it nice to use when you work with sparse tables and it generally gives more clarity to SP code.

    -- create dummy procedure

    IF OBJECT_ID ('Proc1') IS NOT NULL

    DROP PROCEDURE Proc1

    GO

    CREATE PROCEDURE Proc1

    AS

    SELECT 1, 2

    UNION

    SELECT 2, 1

    go

    exec Proc1

    go

    -- table variable example

    DECLARE @vartable TABLE (

    col1INT

    ,col2VARCHAR(10)

    ,col3FLOAT

    )

    INSERT @vartable (col1, col2)

    EXEC Proc1

    SELECT * FROM @vartable

    INSERT @vartable (col2, col3)

    EXEC Proc1

    SELECT * FROM @vartable

    -- temp table example

    CREATE TABLE #temptable (

    col1INT

    ,col2VARCHAR(10)

    ,col3FLOAT

    )

    INSERT #temptable (col1, col2)

    EXEC Proc1

    SELECT * FROM #temptable

    INSERT #temptable (col2, col3)

    EXEC Proc1

    SELECT * FROM #temptable

    -- cleanup

    DROP TABLE #temptable

    DROP PROCEDURE Proc1

    Cheers

    Simone Gigli