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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:17:34+00:00 2026-06-02T16:17:34+00:00

My procedure is: CREATE PROCEDURE [dbo].[sp_SavePost] @PostTitle NVARCHAR(max), @PostDescription NVARCHAR(max), @PostDate DATETIME, @Author NVARCHAR(100),

  • 0

My procedure is:

CREATE PROCEDURE [dbo].[sp_SavePost]
    @PostTitle NVARCHAR(max),
    @PostDescription NVARCHAR(max),
    @PostDate DATETIME,
    @Author NVARCHAR(100),
    @Tag NVARCHAR(250), --it bring c#,asp.net,mvc
    @Category NVARCHAR(250)
AS
BEGIN
   INSERT INTO [dbo].[ForumPost](PostTitle, PostDescription, PostDate,
                                 Author, Tag, Category)
   VALUES(@PostTitle, @PostDescription, @PostDate,
          @Author, @Tag, @Category)
END

Table [dbo].[ForumPost] has postid which is auto increment. There is another tables called Tag. In a same procedure I want to insert a value into Tag table which has column postid and tag. But unable to insert a value in tag table. Means if postid=2 I want a result like this.

Table tag

postid | tag
------------
2      | c#
2      | asp.net
2      |  mvc

Thanks.

  • 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-02T16:17:34+00:00Added an answer on June 2, 2026 at 4:17 pm

    You need to get the latest inserted identity value and then use it in your second insert:

    CREATE PROCEDURE [dbo].[sp_SavePost]
      .....
    AS
    BEGIN
       INSERT INTO [dbo].[ForumPost](PostTitle, PostDescription, PostDate,
                                     Author, Tag, Category)
       VALUES(@PostTitle, @PostDescription, @PostDate,
              @Author, @Tag, @Category)
    
       -- declare variable to hold newly inserted IDENTITY value
       DECLARE @NewPostID INT
    
       -- fetch the newly inserted IDENTITY value
       SELECT @NewPostID = SCOPE_IDENTITY()
    
       -- use that value in the next INSERT into the "Tag" table
       INSERT INTO dbo.Tag(PostId, ......)
       VALUES(@NewPostID, .......)
    END
    

    As a side-note: you should not use the sp_ prefix for your stored procedures. That’s a prefix that Microsoft has reserved for its own use. There is a risk this will not work properly, or that it might cause slowdowns. I would avoid the sp_ prefix – use something like proc_ or no prefix that all…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following stored procedure to retrieve a new datetime: CREATE PROCEDURE [dbo].[GetTransactionTime]
I have written a simple procedure: CREATE PROCEDURE [dbo].[sp_GetPublishedDocs2] @FromDate as Datetime AS BEGIN
I use this code to define my stored procedure CREATE PROCEDURE [dbo].[SP] (@Country NVARCHAR(20))
CREATE PROCEDURE [dbo].[FlowClientGetNum] (@ID_ListGroupParIzm Integer, @ID_ListParIzm Integer) AS SELECT Number of my @ID_ListParIzm FROM
I want to write a stored procedure like this Create Proc dbo.GetApplicantsByIDs as Select
This is confusing. For this declaration of the stored procedure: CREATE PROCEDURE dbo.JobGet @jobGuid
I have created a stored procedure similar to this simplified example: CREATE PROCEDURE dbo.sp_MyStoredProcedure
I have the following SP: CREATE PROCEDURE [dbo].[sp_LockReader] AS BEGIN SET NOCOUNT ON; begin
I wrote this very simple SP in SQL 2008: Create procedure dbo.GetNextID ( @TableName
I have a stored procudre (SP) as follows: CREATE PROCEDURE [dbo].[UDSPSelectMissing] -- paramters omitted

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.