Insert stored procedure output to a table and add datetimestamp

  • Hi All,

    I have a need to insert stored procedure output a table and in addition to that add a datetimestamp column.. For example, Below is the process to get sp_who output into Table_Test table. But I want to add one additional column in Table_test table with datetimestamp when the procedure was executed.

    insert into Table_Test execute sp_who

    any help will be highly appreciated.

    Thanks.

  • something like this:

    add a column "when datetime" to your table then:

    begin tran

    declare @when datetime = current_timestamp;

    insert into table

    exec sp_who2

    update table

    set when = @when

    where when is null

    commit

    Gerald Britton, Pluralsight courses

  • Or put a DEFAULT (GetDate() / GetUTCDate()) constraint on the new column.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

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

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