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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:39:50+00:00 2026-06-05T22:39:50+00:00

How can I create a stored procedure to update the Std_Course’s column based on

  • 0

enter image description here

How can I create a stored procedure to update the Std_Course’s column based on the Id and Name parameter, OR inserts a new row if the Id and Name does not exist

  • 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-05T22:39:51+00:00Added an answer on June 5, 2026 at 10:39 pm

    Try something like this:

    CREATE PROCEDURE dbo.proc_InsertOrUpdate
        @ID INT, @Name VARCHAR(50), @StdCourse INT
    AS 
    
        IF EXISTS (SELECT * FROM dbo.YourTable WHERE ID = @ID AND Name = @Name)
    
            UPDATE dbo.YourTable
            SET Std_course = @StdCourse
            WHERE ID = @ID AND Name = @Name
    
        ELSE    
    
            INSERT INTO dbo.YourTable(ID, Name, Std_Course)
            VALUES(@ID, @Name, @StdCourse
    

    Update: since you’re on SQL Server 2008, you could also use a simple MERGE statement – either directly “inline” or inside the stored procedure. It would look something like this:

    CREATE PROCEDURE dbo.proc_InsertOrUpdate
        @ID INT, @Name VARCHAR(50), @StdCourse INT
    AS 
        MERGE dbo.YourTable AS t
        USING (SELECT @ID, @Name, @StdCourse) AS Source(ID, NAME, Std_Course) 
        ON source.ID = t.ID AND source.Name = t.Name
    
        WHEN MATCHED THEN
            UPDATE SET Std_Course = @StdCourse
    
        WHEN NOT MATCHED THEN
            INSERT(ID, Name, Std_Course)
            VALUES(source.ID, source.Name, source.Std_Course);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we create a temporary table from the stored procedure results dynamically? I do
Can any one tell me if its possible to create a stored procedure in
I'm creating a stored procedure that will create 3 triggers (insert, update, delete) given
I have a stored procedure CREATE procedure [dbo].[get_unique_identifier] AS DECLARE @ret_val INT UPDATE seq
Can't find the solution. I'm having the following stored procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_process_upload_log`(
I want to update a table's column using the results of a stored procedure
I have a stored procedure in MySQL that should update a column in a
How can I create an Oracle stored procedure which accepts a variable number of
Can I create tables using Stored Procedures? I am using MySQL. I had searched
I can't seem to find the syntax for editing an already-created stored procedure in

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.