If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > UPDATE and INSERT/ADD NEW in one query?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-04, 02:12
deltam deltam is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
UPDATE and INSERT/ADD NEW in one query?

I need to do a single query that updates a date field in one table... then adds a new record in another table.

Here's the table/field that I need to update and where the primary key is pulled from to Add a New record in other table:

tTenant
ten_id (the ID field/primary key)
ten_RentAppliedMonth (is a date field in format #m/d/yyyy# or NULL)
ten_moved_date (is a date field in format #m/d/yyyy# or NULL)
ten_rent (currency)
ten_newtenantflag (true/false flag)

I need to do pull a query on tTenant where
ten_RentAppliedMonth is NULL OR <= #7/1/2004#
AND ten_moved_date is NULL
AND ten_newtenantflag is FALSE

then update ten_RentAppliedMonth to #7/1/2004#

with the ten_id, and ten_rent values from above, i need to create a new record in other table.

UPDATE tTenant, tTransactions
SET tTransactions.tran_TenantID = [tTenant.ten_id],
tTransactions.tran_LineBalance = [tTenant.ten_rent],
tTransactions.tran_TransactionDate = #7/1/2004#,
tTransactions.tran_Rent = [tTenant.ten_rent],
tTransactions.tran_TransactionMemo = "Rent posted by BATCH",
tTransactions.tran_Initials = "BATCH",
tTenant.ten_RentAppliedMonth = #7/1/2004#
WHERE (((tTenant.ten_RentAppliedMonth) Is Null)
AND ((tTenant.ten_newtenantflag)=False)
AND ((tTenant.ten_moved_date) Is Null))
OR (((tTenant.ten_RentAppliedMonth)<#7/1/2004#))

Can this all be done in one query?

TIA!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On