469,356 Members | 2,322 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Multiple table value insertion with single Stored procedure

Hi Every one !

I need to insert a set of values which are passed thru the parameter ,Below is the code to do the Single table insertion , Now I need to do multiple table insertion ie, to insert values with the addtional parameter in another table but using the same stored procedure !!

CREATE procedure [dbo].[Pro_SIDN]
@SID int,
@FirstName varchar(10),
@MiddleName varchar(10),
@LastName varchar(10),
@FullName varchar(10),
insert into tableA(SID,Firstname,Middlename,Lastname,Fullname)
values (@SID,@FirstName,@MiddleName,@LastName,@FullName)

Kindly provide me with some sample code ASAP !
Thanks in advance !
Jul 10 '07 #1
2 2437
Motoma
3,237 Expert 2GB
Please do not post questions to the Articles section of the site. I have moved your question to the appropriate forum; hopefully you will find more help there.
Jul 11 '07 #2
Infide
28
Hi Every one !

I need to insert a set of values which are passed thru the parameter ,Below is the code to do the Single table insertion , Now I need to do multiple table insertion ie, to insert values with the addtional parameter in another table but using the same stored procedure !!

CREATE procedure [dbo].[Pro_SIDN]
@SID int,
@FirstName varchar(10),
@MiddleName varchar(10),
@LastName varchar(10),
@FullName varchar(10),
insert into tableA(SID,Firstname,Middlename,Lastname,Fullname)
values (@SID,@FirstName,@MiddleName,@LastName,@FullName)

Kindly provide me with some sample code ASAP !
Thanks in advance !
I'm not exactly sure what you're trying to accomplish. But this may get you started.

Expand|Select|Wrap|Line Numbers
  1. create proc usp_Example
  2. (@Value1 varchar(50),@Value2 varchar(50))
  3. AS
  4. BEGIN
  5.  
  6. DECLARE @ParentTablePrimaryKey INT
  7.  
  8. Insert into ParentTable(Column1)
  9. values(value1)
  10.  
  11. set @ParentTablePrimaryKey = @@IDENTITY
  12.  
  13. Insert into ChildTable(Column1,fk_ParentTableID)
  14. values(@value2,@ParentTablePrimaryKey)
  15.  
  16. END
  17.  
  18.  
You can do as many selects, inserts, deletes and updates as you want in a stored proc. I've seen stored procs over 1000 lines long. If you are working with a relational database with identity columns you will need to grab the identity ID that is auto generated when you insert with the @@Identity.

I think this is what you are going after. If not please provide us with some more details.
Jul 11 '07 #3

Post your reply

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

Similar topics

1 post views Thread by Sylesh Nair | last post: by
2 posts views Thread by Diego | last post: by
2 posts views Thread by =?Utf-8?B?VGVycnk=?= | last post: by
4 posts views Thread by =?Utf-8?B?TWFkaXNvbg==?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.