Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:32:06+00:00 2026-06-04T17:32:06+00:00

I have a situation where I need to insert multiple records/batch insert into a

  • 0

I have a situation where I need to insert multiple records/batch insert into a view which has instead of trigger. How can I retrieve the inserted identity values? I tried using the OUTPUT clause to retrieve the Id from the Inserted table but it always returns null.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:32:08+00:00Added an answer on June 4, 2026 at 5:32 pm

    Using this setup.

    create table InsteadOf
    (
      ID int identity primary key,
      Name varchar(10) not null
    )
    
    go
    
    create view v_InsteadOf
    as
    select ID, Name
    from InsteadOf
    
    go
    
    create trigger tr_InsteadOf on InsteadOf instead of insert
    as
    begin
      insert into InsteadOf(Name)
      select Name
      from inserted
    end
    

    The statement

    insert into v_InsteadOf(Name)
    output inserted.*
    select 'Name1' union all 
    select 'Name2'
    

    Will give you an error.

    Msg 334, Level 16, State 1, Line 4 The target table ‘InsteadOf’ of the
    DML statement cannot have any enabled triggers if the statement
    contains an OUTPUT clause without INTO clause.

    Using an INTO clause with the insert instead.

    declare @IDs table(ID int, Name varchar(10))
    
    insert into v_InsteadOf(Name)
    output inserted.* into @IDs
    select 'Name1' union all 
    select 'Name2'
    
    select *
    from @IDs
    

    Gives you 0 as a value not null.

    ID          Name
    ----------- ----------
    0           Name1
    0           Name2
    

    You can put the output clause in the trigger.

    create trigger tr_InsteadOf on InsteadOf instead of insert
    as
    begin
      insert into InsteadOf(Name)
      output inserted.*
      select Name
      from inserted
    end
    

    And the output will be generated for you when you do the insert.

    insert into v_InsteadOf(Name)
    select 'Name1' union all 
    select 'Name2'
    

    Result:

    ID          Name
    ----------- ----------
    1           Name1
    2           Name2
    

    Update:
    To capture the output from the insert statement you can use insert into ... exec (...)

    declare @T table
    (
      ID int,
      Name varchar(10)
    )
    
    insert into @T
    exec
      (
        'insert into v_InsteadOf(Name)
         values (''Name1''),(''Name2'')'
      )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation in which i'm compelled to retrieve 30,000 records each to 2
I have a situation where I need to programmatically set something that has a
I have a situation where I need to know which features are to be
I have this situation where I need to modify the insert command after is
I have a situation similar to the following question: Insert Data Into SQL Table
I am using EF4 and I have a situation where I need to insert
I have a situation where I need to merge two product tables into one
I have cca 25 databases which I need to consolidate into 1 database. First
Bit rusty in sql I have a situation where I need to insert a
I have a situation as below in which I need to pass a C-style

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.