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

  • Home
  • SEARCH
  • 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 7875825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:03:59+00:00 2026-06-03T03:03:59+00:00

The need to insert values from 3 tables into another table called myTable .

  • 0

The need to insert values from 3 tables into another table called myTable. The required fields in myTable are:

[Id_student] int,
[id_subjects] int
[degrees] float
[st_Name] nvarchar(30) 
[Id_Class] int
[Id_Group] int 
[Class] nvarchar(15)
[group] nvarchar(15))` ..

I created the stored procedure below. But after viewing the table I found that only the passed parameters were saved! ie @Id_student , @id_subjects , @degrees. Can anyone explain what is wrong with this code?

CREATE storedprocedure mySp_myTable_insert
        @Id_student  int,
        @id_subjects int,
        @degrees     int
as

DECLARE @st_Name nvarchar(30) 
SELECT @st_Name  = pst.st_Name  FROM dbo.sudents  AS pst where pst.id_student=@id_student ;

INSERT [myTable]
    (
        [Id_student],
        [id_subjects],
        [degrees],
        [st_Name],
        [Id_Class],
        [Id_Group],
        [Class],
        [group]
    )

    (select
        @Id_student,
        @id_subjects,
        @degrees,
        @st_Name
        ,tc.Id_Class
        ,tg.Id_Group
        ,tc.Class
        ,tg.group
    from dbo.subjects sbj 
    inner join tGroup tg 
    inner join tClass tc
        on tc.Id_Class=tg.Id_Class 
        on sbj.Id_Group =tg.Id_Group 
    where sbj.id_subjects=@id_subjects)
  • 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-03T03:03:59+00:00Added an answer on June 3, 2026 at 3:03 am

    I think you should drop the parentheses around the SELECT statement and fix the order of the join–on keywords/clauses.

    Try this version:

    CREATE storedprocedure mySp_myTable_insert
            @Id_student  int,
            @id_subjects int,
            @degrees     int
    as
    
    DECLARE @st_Name nvarchar(30) 
    SELECT @st_Name  = pst.st_Name  FROM dbo.sudents  AS pst where pst.id_student=@id_student ;
    
    INSERT [myTable]
        (
            [Id_student],
            [id_subjects],
            [degrees],
            [st_Name],
            [Id_Class],
            [Id_Group],
            [Class],
            [group]
        )
    select
        @Id_student,
        @id_subjects,
        @degrees,
        @st_Name
        ,tc.Id_Class
        ,tg.Id_Group
        ,tc.Class
        ,tg.group
    from dbo.subjects sbj 
    inner join tGroup tg on sbj.Id_Group =tg.Id_Group
    inner join tClass tc on tc.Id_Class=tg.Id_Class 
    where sbj.id_subjects=@id_subjects
    
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to insert values into a table. But my condition is that I
I need to write a script to insert data selected from one table into
I have two tables and need top copy one to another INSERT INTO tbl_new
I need to insert values in to the db. INSERT INTO tblname(f1,f2,f3) SELECT f1,f2,f3
Please I need your help with my script. I'm trying to insert values into
I have comma-separated values. I need a query to insert into SQL Server 2008
I need to insert about 1.8 million rows from a CSV file into a
I'm inserting records from one sql server db into another. I need to get
I have a table SINVOICE and another table called SINVOICE_LINE . I need to
I need to insert multiple records into a table. The number of records depend

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.