anil john

anil john

  • NA
  • 156
  • 209.9k

stored procedure

Aug 31 2012 7:58 AM
i have written a sp for cheching the existance of a user,is this code right / wrong but i got wrong results
my sp:

ALTER PROCEDURE dbo.sp_UserDetailsInsertUpdate
    (
    @iUid int,
    @vUserName varchar(50),
    @vUserId varchar(50),
    @vPassword varchar(50),
    @iUserLevel int,
    @blockType int
    )
   
AS
    SET NOCOUNT ON
    If(@blockType=0)
    Begin
    IF EXISTS(SELECT vUserId,iUserLevel FROM tblUserDetails WHERE vUserName=@vUserName AND iUserLevel=@iUserLevel)
    RETURN
    ELSE
    INSERT INTO tblUserDetails(vUserName,vUserId,vPassword,iUserLevel)VALUES(@vUserName,@vUserId,@vPassword,@iUserLevel)
    select @@identity as RowID
    End
    ELSE IF(@blockType=1)
    Begin
    UPDATE tblUserDetails SET vUserName=@vUserName,
    vUserId=@vUserId,vPassword=@vPassword,
    iUserLevel=@iUserLevel WHERE iUid=@iUid
    SELECT @iUid As RowID
    End
    RETURN

Answers (1)