473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

return identity column value from Table after inserting row

45
Hi All,


I am inserting data into Employee table using stored procedure.In employee table EmpNo is identity column.Once i insert data into table stored procedure should EmpNo i.e identitycolumn value.

Please correct my stored procedure to returm EMpNo Identity column after inserting row.
Expand|Select|Wrap|Line Numbers
  1. alter procedure SAR_Sp_AddEmployee(@EmpName varchar(10),@CampaignID int,@startDate datetime)
  2. as 
  3.  insert into EmpMaster values(@EmpName,@CampaignID,@startDate)
Sep 29 '10 #1
5 2742
Frinavale
9,735 Expert Mod 8TB
What database management system are you using?

-Frinny
Sep 29 '10 #2
mzmishra
390 Expert 256MB
In sql server it is
Expand|Select|Wrap|Line Numbers
  1. alter procedure SAR_Sp_AddEmployee(@EmpName varchar(10),@CampaignID int,@startDate datetime)
  2.     as 
  3.      insert into EmpMaster values(@EmpName,@CampaignID,@startDate)
  4.     SELECT SCOPE_IDENTITY()
Sep 29 '10 #3
NareshN
45
Hi Frinavale,

I am using sqlserver 2005
I got solution for that
Sep 29 '10 #4
NareshN
45
Hi,

This code is working for me.
Expand|Select|Wrap|Line Numbers
  1. declare @InsertedEmpID int
  2.  SET @InsertedEmpID = SCOPE_IDENTITY()
  3. SELECT @InsertedEmpID
Thanks
Sep 29 '10 #5
Frinavale
9,735 Expert Mod 8TB
NareshN, could you please mark mzmishra's reply (post #3) as the answer to your question?

Thanks,

-Frinny
Sep 29 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gunnar Vøyenli | last post by:
Hi (SQL Server 2000) I have an existing table (t) with a column that is NOT an identity column (t.ID), but it has manually inserted "row numbers". I want to make this column become an identity...
2
by: (Pete Cresswell) | last post by:
This doesn't work because the first INSERT is creating multiple records for multiple projects. @@IDENTITY, then, contains the Identity column value for the last tblWeekReportedLine record...
2
by: Devesh Aggarwal | last post by:
Hi, I have a backup and restore module in my project. The backup uses a typed dataset object (XSD) to get the data from database and creates a xml file as the backup file (using the WriteXml...
0
by: lwoods | last post by:
I need to set an IDENTITY column value to a new starting point. How do I do this? TIA, Larry Woods
4
by: UDBDBA | last post by:
Hi: we have column with GENERATED ALWAYS AS DEFAULT. So, we can insert into this column manually and also let db2 generate a value for this column. Given a scenario, how can i find the NEXTVAL...
1
by: Hongyu Sun | last post by:
Hi, All: Please help. I use sql server as back end and Access 2003 as front end (everything is DAO). A table on SQL server has an identity column as the key. We have trouble on adding...
6
by: Christopher Lusardi | last post by:
How can I fix this? When I do the below I get the error message: "Cannot insert explict value for identity column in table 'Employees' when IDENTITY_INSERT is set to OFF." To get this message,...
5
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as...
2
by: sajithamol | last post by:
I have a table with an Identity column. The latest Identity value is 1298. A row with Identity 324 was deleted by mistake and I need to insert it now. But if I insert it now it will have Identity...
6
Curtis Rutland
by: Curtis Rutland | last post by:
OK, here's what I'm doing. I have a SQL Server 2005 table with an auto-number Identity column that I will be inserting to. I used the DataSet designer to add a table adapter to my DataSet to which...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.