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 6696797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:23:02+00:00 2026-05-26T06:23:02+00:00

Database : SQL Server 2008 Is there a way to have an insert statement

  • 0

Database : SQL Server 2008

Is there a way to have an insert statement return a value in SQL Server,

There is a similar question in

Return a value from a insert statement , which talks about ORACLE .

I don’t work with databases much, and not aware of ORACLE/SQL Server much, so sorry to ask it all over again.

For simplicity let me provide a small example :

The table EmpDetails has EmpiD and EmpName. The value of EmpID is autogenerated by the database.

INSERT INTO EMPDETAILS VALUES("John")

Now I want to get the value of EmpID associated with John

I don’t want a stored procedure, I want a SQL statement only .

  • 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-05-26T06:23:02+00:00Added an answer on May 26, 2026 at 6:23 am

    Yes – you can use the little known and little used OUTPUT clause in your INSERT statement

    INSERT INTO dbo.YourTable(col1, col2, col3, ...., ColN)
    OUTPUT Inserted.Col1, Inserted.Col5, Inserted.ColN
    VALUES(val1, val2, val3, ....., valN)
    

    This returns a normal set of data, that you can deal with as you need to.

    As the MSDN docs show, you can also send the OUTPUT values into e.g. a table variable or temp table for later use, if you need to.

    To answer your updated question, use this:

    INSERT INTO dbo.EMPDETAILS(EmpName)
    OUTPUT Inserted.EmpID
    VALUES("John")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MS SQL Server 2008 Database, from which I am fetching data
SQL Server 2008 Database Question. I have 2 tables, for arguments sake called Customers
I have within my Sql Server 2008 database a trigger which will run on
I have a database in SQL Server 2008, and there are a lot of
I have to move an entire database from a SQL Server 2008 machine to
Is there a way to validate programmability objects in SQL Server 2008? I have
I have a SQL-Server 2008 database and a schema which uses foreign key constraints
A have a database on MS-SQL Server 2008 that is growing a lot, year
I have SQL Server 2008 Ent and OLTP database with two big tables. How
Question: The new SQL Server 2008 database returns me values formatted English (date/float). Is

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.