Click here to Skip to main content
11,642,216 members (61,169 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 GimmeCode , +
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
Edited 11-Oct-12 3:57am
v2
Comments
joshrduncan2012 at 11-Oct-12 9:55am
   
It's not clear what your question is.
Adersh Ram at 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
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
0 DamithSL 220
1 Sergey Alexandrovich Kryukov 154
2 Afzaal Ahmad Zeeshan 145
3 OriginalGriff 135
4 Mika Wendelius 80
0 Mika Wendelius 460
1 DamithSL 353
2 OriginalGriff 315
3 Sergey Alexandrovich Kryukov 179
4 Afzaal Ahmad Zeeshan 169


Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2015
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