Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:39:18+00:00 2026-06-15T19:39:18+00:00

I am trying to create a stored procedure to insert data into 2 tables

  • 0

I am trying to create a stored procedure to insert data into 2 tables in SQL Server.

I have tried putting the join in all different positions of the code and still get an error.

 CREATE PROCEDURE sp_Insert_Person
 @s_FirstName nvarchar(50),
 @s_Surname nvarchar(50),
 @s_AddressLine1 nvarchar(50),
 @s_AddressLine2 nvarchar(50),
 @s_Postcode nvarchar(10),
 @s_Phone nvarchar(50),
 @s_Department nvarchar(50)
 AS
BEGIN
INSERT INTO 
        tbl_person(FirstName, Surname, AddressLine1, AddressLine2, 
                   Postcode, Phone, tbl_Department.Department)
INNER JOIN tbl_person
ON  tbl_person.DepartmentID = tbl_Department.DepartmentID

VALUES (@s_FirstName,
        @s_Surname,
        @s_AddressLine1,
        @s_AddressLine2,
        @s_Postcode,
        @s_Phone,
        @s_Department)

END

I have tried the join at the end and at the beginning I have looked all over for insert joins, wondered if i was just getting it all wrong.

I have a department table and a person table and thought I would be able to access the department table through the FK DepartmentID which I have in the Person table, as is the PK in the Department table

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:39:19+00:00Added an answer on June 15, 2026 at 7:39 pm

    I think something like this

    INSERT INTO tbl_person
                         (FirstName,
                         Surname, 
                         AddressLine1, 
                         AddressLine2, 
                         Postcode, 
                         Phone, 
                         DepartmentID)
    Select @s_FirstName,
            @s_Surname,
            @s_AddressLine1,
            @s_AddressLine2,
            @s_Postcode,
            @s_Phone, 
            tbl_Department.DepartmentID 
    from  tbl_person 
    join DepartmentID
    ON  tbl_person.DepartmentID = tbl_Department.DepartmentID 
    where tbl_Department.Department = @s_Department
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a stored procedure in SQL Server 2008 which can
I am trying to insert Data into my Sql-Server database though C#. I'm Calling
I am trying to create a stored procedure in SQL Server 2008. According to
I am trying to create a stored procedure using pass-through query in SQL Server
I'm trying to create a stored procedure that will search all user created tables
I have an already existing stored procedure. But when I am trying to create
I'm trying to create stored procedure in MySQL Community Server 5.5.16: CREATE UNIQUE SEQUENCE
I have a stored procedure that I'm trying to debug (T-SQL). It contains creates
I'm trying to execute a stored procedure in PHP that inserts data into a
I'm trying to insert data into a table using a plpgsql function or stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.