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.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

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

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