Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Need help for Insert Into Statement

Hi,

I am new to Sql Server 2000.I am trying to do something but have not been able to figure out how to insert data on two different tables from one submission form.

I have created two tables t_Caller (CallerId, CallLastName, CallFirstName) and
other table called t_Complainent(ComId, CallerId, ComLastName, ComFirstName). Where CallerId is the primary key for t_Caller table and ComId is the primary key for the t_Complainent table.

For example, I have a form that asks for the following data (from users registering):

Caller's Last Name
Caller's First Name

Complainent's Last Name
Complainent's First Name

I would like to insert CallerId, Caller's Last Name and First Name into table t_Caller and ComId, CallerId (Same as t_Caller table's CallerId) Complainent's Last Name and First Name in to t_Complainent table using only one INSERT statement. I don't have any clue how to do it?

I am using SQL Server 2000 for this.

How would I insert data from one form into two tables?
Please help me asap.

Thanks for you help,

Vishal
[1171 byte] By [vishal.joshi1] at [2007-11-11 7:43:31]
# 1 Re: Need help for Insert Into Statement
You need an INSERT statement for each table. If you want you can wrap them in a transaction but you still need multiple INSERT statements. The following link should help:

http://www.sqlteam.com/item.asp?ItemID=15583
pclement at 2007-11-11 23:47:41 >
# 2 Re: Need help for Insert Into Statement
Thanks Paul,

Thaks for your suggestion. It helped a lot.
vishal.joshi1 at 2007-11-11 23:48:46 >