Using SProc to insert data

  • I have an existing sproc that returns 15 fields and I'd like to use this to insert data into a table that only has 10 fields. Is there any way to ignore the extra fields in an Insert statement or do i need to create a new sproc?

    TIA

    Dean

  • Your stored proc returns a result set I assume, so I assume you're asking if you can do something like:

    INSERT INTO TABLE (COLUMNS)

    EXEC StoredProc

    To my knowledge, no, you can't do that. What you can do is create a temp table or table variable, insert it into that table, and then from there, you can insert the values you want into your table.

    EG:

    DECLARE @TempTable TABLE

    (

    AllColumnsFromStoredProc

    )

    INSERT INTO @TempTable (AllColumnsFromStoredProc)

    EXEC StoredProc

    INSERT INTO RealTable (ColumnsToInsert)

    SELECT ColumnsToInsert FROM @TempTable

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply