Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Bes way to insert data into two table.

Author  Topic 

kidaduo
Starting Member

45 Posts

Posted - 2008-05-02 : 13:54:49
I'm passing data into sql proc. then insert into two diffrent tables. The two table dont have 1:1 relations. I'm trying to come up with the best way to insert the values into these two table. Here is what I have-- any suggestion?

fyi. I will love the proc to check errors during the process

CRETAE PROCEDURE dbo.two_tableProc
@File1 varchar(5),
@File2 varchar(5),
@SystemDate datetime,
@RecordCt1 varchar(100)
@RecordCt2 varchar(100)
@RecordID INT

as

INSERT INTO tbl1
(
File1,
RecordCt1,
SystemDate

)
VALUES (@File1,@RecordCt1,@SystemDate)

INSERT INTO tbl2
(
File2,
RecordCt2,
RecordID
)
VALUES (@File2,@RecordCt2,@RecordID)

GO

Josephine

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-05-03 : 07:54:37
I would add a BEGIN TRANSACTION..COMMIT TRANSACTION

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -