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 @ParLngId, I check if there is a such data in a table, if yes, I return the value, if not I insert one and return the variable which contains the Id of the inserted line... But now it shows me an SqlException:
Subquery returned more values. This is not permitted when the subquery follows =,! =, <, <=,>,> = Or when used as an expression.
Somebody has a solution ?
CREATE PROCEDURE: "Avoid the use of the sp_ prefix when naming procedures. This prefix is used by SQL Server to designate system procedures. Using the prefix can cause application code to break if there is a system procedure with the same name."