I have a form that will look up a customer and a caller. The customer will always be in the db but the caller and his info may not be.
I have an address table that holds the address of both client and caller. Its a shared table. I also have another table for the caller's name, phone number and ssn.
There can be a few different scenarios when saving this data and I am confused as to how to handle it. Maybe someone can put me back on track.
The way I thought about doing this is to query the db for the following:
1. Query the db for the caller's address
2. Query the db for the caller's name
If found:
Query for the existing PK.
If not found:
Query for the Max() PK columns respectively to do the insert.
I am using transactions on these tables and the reason why I am querying for the PKs is because there is no way to get the last insert id from the table in a transaction when there is more than 1 table being affected. I hope that makes sense.
What I have are a lot of these small queries that are making me crazy. Is there a way to condense these queries into one? Here is an example of just the address queries:
Quote:
SELECT
t1.address_id
FROM
address AS t1
WHERE
address1 = ''
|
Quote:
SELECT
Max(t1.address_id) AS Max
FROM
address AS t1
|
Is it possible to condense these two queries into one?
Thanks,
Frank