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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:18:06+00:00 2026-05-15T18:18:06+00:00

how to write a if else statement to insert query for showing the error

  • 0

how to write a if else statement to insert query for showing the error in stored procedure

below is my stored procedure.I want to show a error message when already inserted student_id is insert again..Student_id is primary key so its show error in my code but i dono how to get that error and show ….how to do friends plz help me…..

ALTER PROCEDURE [dbo].[spinsertstudentapplication] 
    -- Add the parameters for the stored procedure here
    @Student_id             nvarchar(50),   
    @Select_Country         nvarchar(50),
    @Select_State           nvarchar(50),
    @Select_Franchise       nvarchar(50),
    @Select_Sensei          nvarchar(50),
    @Enter_Student_Name     nvarchar(50),
    @Enter_Student_Address  nvarchar(50),
    @Students_Father_Name   nvarchar(50),
    @Student_DOB            datetime,
    @Gender                 bit,
    @Group                  nvarchar(50),
    @Enter_Kyu              nvarchar(50)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here 
    insert into StudentApplication(Student_id,Select_Country,Select_State,Select_Franchise,Select_Sensei,Enter_Student_Name,Enter_Student_Address,Students_Father_Name,Student_DOB,Gender,[Group],Enter_Kyu)values(@Student_id,@Select_Country,@Select_State,@Select_Franchise,@Select_Sensei,@Enter_Student_Name,@Enter_Student_Address,@Students_Father_Name,@Student_DOB,@Gender,@Group,@Enter_Kyu)

END
  • 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-15T18:18:06+00:00Added an answer on May 15, 2026 at 6:18 pm

    You can add an output parameter(int/bit) in Sp and set value to that parameter whether record exist or not. Then you can check the output parameter value in Front End. Below I’ve added an output parameter @RecordExist as bit and setting the value 1 when record already exists otherwise setting 0. In front end you can get the Parameter value from SqlCommand after executing the Sp. (SqlCommand.Parameters["@RecordExist"].Value)

    ALTER PROCEDURE [dbo].[spinsertstudentapplication]   
        -- Add the parameters for the stored procedure here  
        @Student_id             nvarchar(50),     
        @Select_Country         nvarchar(50),  
        @Select_State           nvarchar(50),  
        @Select_Franchise       nvarchar(50),  
        @Select_Sensei          nvarchar(50),  
        @Enter_Student_Name     nvarchar(50),  
        @Enter_Student_Address  nvarchar(50),  
        @Students_Father_Name   nvarchar(50),  
        @Student_DOB            datetime,  
        @Gender                 bit,  
        @Group                  nvarchar(50),  
        @Enter_Kyu              nvarchar(50),
        @RecordExist            bit output  -- newly added parameter
     AS  
     BEGIN  
         -- SET NOCOUNT ON added to prevent extra result sets from
         -- interfering with SELECT statements.
         SET NOCOUNT ON;
    
         -- Insert statements for procedure here 
    
    If Exists (Select * from StudentApplication where Student_id = @Student_id)
       Begin
          Select @RecordExist = 1
          return
       End
    
    Else
      Begin
          insert into StudentApplication (Student_id, Select_Country, Select_State,  Select_Franchise, Select_Sensei, Enter_Student_Name, Enter_Student_Address, Students_Father_Name, Student_DOB, Gender, [Group], Enter_Kyu)
    
          Select @Student_id, @Select_Country, @Select_State, @Select_Franchise, @Select_Sensei, @Enter_Student_Name, @Enter_Student_Address, @Students_Father_Name, @Student_DOB, @Gender, @Group, @Enter_Kyu
    
          Select @RecordExist = 0
          return
      End
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I write an IF ELSE statement in a MySQL query? Something like
I want to write an if/else statement that tests if the value of a
I'm trying to write an IF ELSE statement to enable shipping, If user doesn't
I am trying to write an if/else statement that will hide my .thumb <div>
I have this bit of code here. How would I write an if/else statement
How do I write an if - then - else statement in Python so
I am trying to write something comparable to an If, else if, else statement.
I am trying to write a stored procedure that will check for the existence
I'm trying to write an IF ELSE statement nested inside another IF statement. Here's
I'm trying to write a MySQL statement to insert information to a table: $insert

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.