Reputation: 377
i have a stored procedure which first of all checks for some record whether it exists or not. if already exists then executes updates statement (if update statement works fine then returns affected row no else returns a variable with -1000 value) else it selects a variable with value -2000.
Problem is it works fine if i executes it in sql server but when i call it from C# then it returns current_indent('') or only -1 no -1000 or -2000 is returned.
USE [youfuntube]
GO
ALTER PROCEDURE [dbo].[usp_change_pass]
@e_mail varchar(60),
@old_pass varchar(27),
@new_pass varchar(27)
AS
BEGIN
declare @exist int;
Set @exist =0;
Select @exist=COUNT( userinfo_signup.e_mail) from userinfo_signup where userinfo_signup.e_mail=@e_mail;
if(@exist>0)
BEGIN
SET @exist=0;
SELECT @exist= COUNT ( userinfo_signup.e_mail) from userinfo_signup Where userinfo_signup.e_mail=@e_mail And userinfo_signup.password=@old_pass;
if(@exist>0)
Begin
UPDATE userinfo_signup
Set password=@new_pass
Where e_mail=@e_mail AND password=@old_pass;
Select IDENT_CURRENT( 'userinfo_signup');
End
ELSE
begin
Set @exist=-1000;
SELECT @exist;
end
END
ELSE
BEGIN
SET @exist=-2000;
Select @exist;
END
END
GO
Upvotes: 2
Views: 296
Reputation: 919
I would try using the MERGE command instead of an if exists. Here is a simple introduction to the command: http://blog.sqlauthority.com/2008/08/28/sql-server-2008-introduction-to-merge-statement-one-statement-for-insert-update-delete/
Upvotes: 1