Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Unanswered: multi table stored procedures

    Hi,

    I have created a stored procedure that inserts certain values into one table, how do i create a table insert information into more than one table?

    This is the sql for the current procedure:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[StaffInsert]

    @StaffName varchar(50),
    @Telephone varchar(50),
    @Email varchar(65)

    AS
    BEGIN

    INSERT staff(StaffName,Telephone,Email)
    VALUES (@StaffName,@Telephone,@Email)

    END

    what i want to happen is for information to be stored within another table called company which has the following columns:

    Company Name
    Country

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Accept two more parameters for @company_name and @country and add a second INSERT statements between the BEGIN and END section of the procedure
    George
    Home | Blog

  3. #3
    Join Date
    Oct 2009
    Posts
    2
    Hi gvee,

    Would it be like this?

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[StaffInsert]

    @StaffName varchar(50),
    @Telephone varchar(50),
    @Email varchar(65)
    @CompanyName varchar(50),
    @Country varchar(50)

    AS
    BEGIN

    INSERT staff(StaffName,Telephone,Email)
    VALUES (@StaffName,@Telephone,@Email)

    INSERT company(CompanyName,Country)
    VALUES (@CompanyName,@Country)

    END


    thanks for your help

  4. #4
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    yes it would

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •