Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

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

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.


Thanks,
ASPDEV
0
ASPDEV
Asked:
ASPDEV
2 Solutions
 
Dale FyeCommented:
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)
0
 
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
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
 
0
 
ASPDEVAuthor Commented:
Both of your solutions make sense , I will try it.

Thanks,
ASPDEV.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now