Click here to Skip to main content
13,139,496 members (51,930 online)
Rate this:
 
Please Sign up or sign in to vote.
hi frnds i have two table student details and student grade.
Student details contain columns
stu_id integer
stu_name
stu_place

student grade contains columns
stu_id
stu_grade

while saving i am going to send student name and grade,at that time by using single stored procedure i have to auto generate id and insert student details and student grade table.
Posted 11-Oct-12 3:45am
Updated 11-Oct-12 3:57am
v2
Comments
joshrduncan2012 11-Oct-12 9:55am
   
It's not clear what your question is.
Adersh Ram 11-Oct-12 9:59am
   
Hi,

You can get the new id from "SELECT @@IDENTITY", insert the data to grade table using this id.

Thanks
ARam

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi ,
Check this
<br />
use Scope_Identity() or @@idetity 

also check on @@Error if any error happen
Create proc usp_name
( @name  varchar(30),@gard int)
as
begin
declare @id int 
insert into FirstTable
(name)
values
(@name)
set @id = @@identity --or scope_identity
 
insert into Secondtable 
(stid , grade)
value
(@id , @grade 
end

Best Regards
M.Mitwalli
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100