If else in stored procedure sql server

0 votes

I have created a stored procedure as follow:

Create Procedure sp_ADD_USER_EXTRANET_CLIENT_INDEX_PHY
(
@ParLngId int output
)
as
Begin
    SET @ParLngId = (Select top 1 ParLngId from T_Param where ParStrNom = 'Extranet Client')
    if(@ParLngId = 0)
        begin
            Insert Into T_Param values ('PHY', 'Extranet Client', Null, Null, 'T', 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL)
            SET @ParLngId = @@IDENTITY
        End
    Return @ParLngId
End

So I set a variable called @ParLngId, check to see whether a table contains such data, and if it does, return the value; otherwise, I insert one and return the variable containing the Id of the inserted line. However, it now displays a SqlException:

Subquery returned more values. This is not permitted when the subquery follows =,! =, <, <=,>,> = Or when used as an expression.

Does somebody have a solution?

Aug 22 in Database by Kithuzzz
• 12,240 points
26 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Database

0 votes
0 answers

What is the syntax to drop a Stored Procedure in SQL Server 2000?

In SQL Server 2000, how do you ...READ MORE

Aug 25 in Database by Kithuzzz
• 12,240 points
45 views
0 votes
0 answers

Search text in stored procedure in SQL Server

I want to search all of my ...READ MORE

Aug 27 in Database by Kithuzzz
• 12,240 points
16 views
0 votes
0 answers

Loop in stored procedure in SQL server

Writing a stored procedure that calls another ...READ MORE

Aug 28 in Database by Kithuzzz
• 12,240 points
50 views
0 votes
1 answer

How to Execute SQL Server Stored Procedure in SQL Developer?

You don't need EXEC clause. Simply use: proc_name ...READ MORE

answered Sep 16 in Database by narikkadan
• 20,880 points
41 views
0 votes
0 answers

Check if table exists in SQL Server

I want this to be the last ...READ MORE

Aug 21 in Database by Kithuzzz
• 12,240 points
33 views
0 votes
0 answers

SQL Server 2008 - IF NOT EXISTS INSERT ELSE UPDATE

I'm trying to create a time clock ...READ MORE

Aug 28 in Database by Kithuzzz
• 12,240 points
41 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4 in Database by Neha
• 8,920 points
216 views
0 votes
1 answer

Function vs. Stored Procedure in SQL Server

Functions are calculated values that cannot make ...READ MORE

answered Feb 17 in Database by Neha
• 8,920 points

edited Feb 17 by Neha 459 views
0 votes
0 answers

What is a stored procedure?

119 What is a "stored procedure" , how do they work? What ...READ MORE

May 27 in Others by avinash
• 1,840 points
36 views
0 votes
0 answers

SQL Server: Invalid Column Name

I am in the process of changing ...READ MORE

Aug 19 in Database by Kithuzzz
• 12,240 points
117 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP