472,328 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Insert Into Two Tables

Hi,

I have having problems inserting data into two tables.

I have two tables j and b.

there is jid,bBoxtotal, column in j table
there is bjobid,bBoxNumber,bBoxtotal in b table

What I need to do is insert first into j table and get the last jid and insert that into b table column bjobid.

Can anyone please help?

Thanks.
Oct 26 '06 #1
2 2204
Hi ,

You didn't mention which database server you are using. Assuming that you are using SQLServer and jid column in j table is set to default identity.

INSERT INTO j ( bBoxtotal ) VALUES ( 35 ) //inserting into j table

DECLARE @last_id int

SELECT @last_id = max(jid) FROM j //getting the last jid

INSERT INTO b ( bjobid , bBoxNumber , bBoxtotal )
VALUES ( @last_id, 2 , 35) // inserting into b table

Thanks,
Jaya.S
Oct 31 '06 #2
vssp
268 100+
If mysql server how to insert two table ?

vssp
Oct 31 '06 #3

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

Similar topics

2
by: EricRobineau | last post by:
hello I have a DB with many inter-related tables (MySQL) My main table called "content" has almost only foreign keys (integers) some have a 3...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that...
6
by: Larry Johnson | last post by:
I have two similar SQL Server databases each with a table named Payments. PaymentID is an identity field and the primary, unique, key in both...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I...
2
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs...
3
by: nolanmadson | last post by:
I'm creating a front-end for some Teradata user maintenance tables in MS Access. I've started having problems in occasionally not being able to...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.