Skip to content
Loading
  • Sanwar Ranwa
    0
    Hello
     
    We chcek mutliple conditions is store proc  lets see some example of
     
    create proc checkpwd
    (
    @name varchar(50),@pwd varchar(50))
    as
    begin
    if exists(select * from login where name=@name and pwd=@pwd)
    begin
    select 'Name and Password already exits'
    end
    else
    insert into login values(@name,@pwd)
    end
    end
     this proc is used to check single conditons
     
     lets check some more example
     
    ALTER procedure [dbo].[Proc_CheckUser]
    @userid VARCHAR(50),
    @password VARCHAR(50)
    AS
    SET nocount ON
    DECLARE @ReturnVal VARCHAR(500)
    DECLARE @PasswordOld VARCHAR(50)
    SELECT @PasswordOld = password
    FROM Clients
    WHERE username = @userid
    IF ( @PasswordOld IS NULL )
    SET @ReturnVal='1|Incorrect Username'
    ELSE IF ( @PasswordOld = Hashbytes('SHA1', @password) )
    SET @ReturnVal='0|Logged in Successfully'
    ELSE
    SET @ReturnVal='2|Incorrect Password'
    SELECT @ReturnVal
     
    We can check more condition in a proc 
    0