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 1103011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:16:31+00:00 2026-05-17T01:16:31+00:00

I have a Stored procedure, in which I have to insert 3 strings into

  • 0

I have a Stored procedure, in which I have to insert 3 strings into 3 different Tables at a time, each string into each of the 3 tables.
In each table, a unique primary key (rowid) would be generated on insertion of the value.
Now, the Primary Key of first two tables is the Foreign key of the Third Table which as you all know, should not be null.

Here in my SP, insertion of value and generation of RowID (PrimaryKey) is done successfully.
Now I have to pass the two primary keys(Rowids) as values/Parameters(foreignkeys) into the third table, which is returning null.

Here is my SP:-

    (1st Table)    
   INSERT INTO [kk_admin].[FA_Master](FA_Name,FA_CSession,FA_MSession) Values
             (@FA_Name,@Session_Id,@Session_Id)

   SELECT @**FA_ID=FA_ID** FROM [kk_admin].[FA_Master] where FA_Name=@FA_Name  

    (2nd Table)  
   INSERT INTO [kk_admin].[Dept_Master](Dept_Name,Dept_CSession,Dept_MSession) Values  
   (@Dept_Name,@Session_Id,@Session_Id)  

   SELECT @**Dept_id=Dept_id** from [kk_admin].[Dept_Master] where Dept_Name=@Dept_Name   

   (3rd Table)
   INSERT INTO [kk_admin].[Category_Master] (**FA_Id**,**Dept_Id**,Category_Name,Category_CSession,Category_MSession) Values    (@**FA_ID**,@**Dept_Id**,@Category_Name,@Session_Id,@Session_Id)  

Hope everyone understood what I have explained.

Plz Help me,
Iam running out of time.
Plz help me.
Thank You in Advance,
Brightsy

  • 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-05-17T01:16:32+00:00Added an answer on May 17, 2026 at 1:16 am

    You can use an OUTPUT clause (assuming you’re using SQL Server 2005) to capture the primary key for the two rows you’re inserting with the first two queries. You can capture the values into a temporary table. [I previously wrote that you could use a regular variable, but that’s not supported.] Example code:

    CREATE TABLE #FA_Master_ID ( ID int );
    CREATE TABLE #Dept_Master_ID ( ID int );
    
    INSERT kk_admin.FA_Master ( FA_Name, FA_CSession, FA_MSession )
    OUTPUT INSERTED.ID INTO #FA_Master_ID
    VALUES ( @FA_Name, @Session_Id, @Session_Id );
    
    INSERT kk_admin.Dept_Master ( Dept_Name, Dept_CSession, Dept_MSession )
    OUTPUT INSERTED.ID INTO #Dept_Master_ID
    VALUES ( @Dept_Name, @Session_Id, @Session_Id );
    
    INSERT kk_admin.Category_Master ( **FA_Id**, **Dept_Id**, Category_Name, Category_CSession, Category_MSession )
    SELECT  **FA_Id** = ( SELECT TOP 1 ID FROM #FA_Master_ID ),
            **Dept_Id** = ( SELECT TOP 1 ID FROM #Dept_Master_ID ),
            Category_Name = @Category_Name,
            Category_CSession = @Session_Id,
            Category_MSession = @Session_Id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Stored procedure which schedules a job. This Job takes a lot
Hai Techies, I have some stored procedure which was written in SQL server.Now i
I have a Stored Procedure called spGetOrders which accepts a few parameters: @startdate and
I have an MSSQL2005 stored procedure here, which is supposed to take an XML
Which command will executed first,If a stored procedure have individual multiple select commands;
I have a problem with an application which uses the same stored procedure over
I have stored procedure: ALTER PROCEDURE [dbo].[k_ShoppingCart_DELETE] @cartGUID nvarchar AS DELETE FROM [dbo].[k_ShoppingCart] WHERE
I have a strange, sporadic issue. I have stored procedure that returns back 5
I have a stored procedure in SQL 2005. The Stored Procedure is actually creating
I have a stored procedure that consists of a single select query used to

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.