Reputation: 281
Is there any way to check if a record that is being created is the first record or not?
To clear up my question:
If I insert a phone number on a customer, I want to check if it is the first inserted phone number on that customer; if so, I want to set that phone number as primary, any phone numbers entered while the previous phone number still exists, may not be set primary automatically.
Upvotes: 0
Views: 169
Reputation: 5107
Regarding the first, general part of your question: Yes, there is. Query the table where you want to insert a record if it contains any records. If yes, you are not inserting the first record.
For your more specific scenario regarding customer phone numbers, the table to query would be LogisticsElectronicAddress
. You might also want to take a look at the phone
method of table CustTable
, which will give you the primary phone number of a customer. If this method does not return a phone number, you at least know that the customer has no primary phone number yet. Depending on your requirements, this may already be the information that you need. Otherwise the code in this and the subsequent called methods will give you an idea how you can query LogisticsElectronicAddress
table for existing records.
Upvotes: 3