After SQL INSERT,Show the INSERTED RECORDS or Records afftected  in SQL Server 2005

Posted on 2011-05-05
Last Modified: 2012-05-11
Hello Experts,

I have some special req. where I Insert records from a Text file, once Inserted I need to show the Records successfully Inserted.

For Instance, if i have inserted 10 records, I can get records afftected count. But I need the Result Set of the records affected with the Insert.

Question by:ASPDEV
    LVL 47

    Assisted Solution

    by:Dale Fye (Access MVP)
    Well, if the table you are inserting into has a Date/Time field with a default value of the current date/time (not sure what that looks like in SQL Server), then those records would all have the same date/time value and you could select them with SQL that looks like:

    SELECT * FROM yourTable where [DateTimeField] = (SELECT MAX([DateTimeField]) FROM yourTable)
    LVL 16

    Accepted Solution

    how are you inserting data in table,
    if there is any identirty field/timestemp on the table? if yes then you can use that to get inserted records.

    let say you are using some sp and have identity column then you can use @@identity to get id of the related row. and then can get all reated records again.

    if you are using timestemp then you can get that with help of getdate method

    Author Closing Comment

    Both of your solutions make sense , I will try it.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    SQL Schedule Job 1 12
    VB Access SQL question 2 16
    What does this mean? 6 24
    Need T-SQL Statement grouping households 6 23
    In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now