Link to home
Start Free TrialLog in
Avatar of hazemfadl
hazemfadlFlag for Egypt

asked on

How do I create a function to add record to 2 tables.

If I have the following tables:
1. Article (ArID  ArTitle)
2. Author (AuhtID  AuthName)  (Please note that AuthID is not Autonumber)
3. ArAuthor (ArID  AuthID) --> used to link Article with Authors

And I want to implement the following as function:

Link AuthorName to Article (Inputs: ArID, AuthName)
1. Check if the AuthName Exists in Author (use "=" not "like")
        a. If (Yes):
                i. Add ArID and AuthID to ArAuthor
        b. If (No):
                i. Add Author to Author table (please note AuthID is not autonumber)
                ii. Add ArID and new AuthID to ArAuthor
2. Returns AuthID (what ever add new or it is already in Auth Table)

Thank you,
ASKER CERTIFIED SOLUTION
Avatar of jorge_toriz
jorge_toriz
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark Wills
@jorge_toriz, you forgot to return the @Authid...

simply add    select @Authid     before the END (and after the insert).
Is not necesary to make an explicit return ... check that @AuthId parameter is OUTPUT
so it is, did not read the parameter lines all that closely - sorry 'bout that.