insert with output clause

  • This was removed by the editor as SPAM

  • N_Muller wrote:

    I can always change a select-insert into a merge. There's never going to be a "WHEN MATCHED". Must try to see if it solves the problem.

    Yep

    declare @master table(id int identity(1,1), name varchar(10));
    declare @master_values table(id int identity(1,1), name varchar(10), value int);

    insert @master(name) values ('kim'), ('jack');

    insert @master_values(name, value)
    select m.name, l.value
    from
    @master m
    join
    (values (1, 10), (2, 15 )) as l (id, value) on l.id = m.id;

    declare @values table (id int, value int, dt datetime2(2) default(getdate()));
    declare @lastupdate table (name varchar(10), value int, dt datetime2(2));

    merge
    @values as t
    using
    @master_values as src
    on
    1=0
    when not matched then
    insert values(src.id, src.value, getdate())
    output
    inserted.id, src.name, inserted.value;

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • Hello,

    Your examples are really apt.

    I also face problem in the creation of columns sometimes,

    A copy of an existing table can also be created using the CREATE TABLE really easily.

    The new table gets the same column definitions and even all columns or specific columns can be selected.

    If you create a new table using an existing table, the new table will be filled with the existing values from the old table.

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

Viewing 13 posts - 16 through 27 (of 27 total)

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