Click here to Skip to main content
Sign Up to vote bad
good
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:45
Edited 11 Oct '12 - 3:57

Comments
joshrduncan2012 - 11 Oct '12 - 9:55
It's not clear what your question is.
Adersh Ram - 11 Oct '12 - 9:59
Hi, You can get the new id from "SELECT @@IDENTITY", insert the data to grade table using this id. Thanks ARam

1 solution

Hi ,
Check this
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 206
1 Richard MacCutchan 145
2 Tadit Dash 140
3 Sergey Alexandrovich Kryukov 135
4 Santhosh G_ 125
0 Sergey Alexandrovich Kryukov 10,294
1 OriginalGriff 7,955
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,159


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid