Results 1 to 4 of 4
  1. #1
    Join Date
    May 2013
    Posts
    7

    Unanswered: Insert statement and column names

    Hello,

    Can an INSERT statement also return all columns inserted as a result set? If so what clause of the INSERT statement does this?

    Thanks,

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I don't know of any way to do this with an INSERT statement. It could be done with a stored procedure, and there might be a way to do it with a MERGE statement.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    OUTPUT Clause (Transact-SQL)
    Code:
    INSERT INTO schema.object (list, of, columns)
      OUTPUT inserted.list, inserted.of, inserted.columns
    VALUES ('output', 'clause', 'rules')
    ;
    George
    Home | Blog

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I hadn't realized that the OUTPUT clause column list supported the use of * to get all of the columns. That's a neat feature!

    Just beware, the data returned is before any triggers execute, and gets rather muddled if a trigger returns any rows!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •