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

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's what I would do: Create your item renderer derived… May 16, 2026 at 10:13 am
  • Editorial Team
    Editorial Team added an answer It turns out my view's bounds were set to the… May 16, 2026 at 10:13 am
  • Editorial Team
    Editorial Team added an answer The tutorial is perfect but the simulator has certain constraints.… May 16, 2026 at 10:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Im trying to write an SQL query that will check in the table ‘persons’
If I want to write a custom command for a button control in WPF,
I want to write url link in views, and then return to template. views.py
How can I change the MySQL query delimiter using the C API? I tried
Quoting MySQL INSERT manual - same goes for UPDATE: Use the keyword DEFAULT to
I want to update a table called Sorels_ext from a table called Sorels. The
Having problem understanding Delegate error. Error says expression expected, How do I fix? Thanks
I'm attempting to write a performance testing function that can take any function, run
So supposedly in the iOS 4 SDK you can edit and write to the
Why is it that below code prints 'None' as well as what I tell

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.