Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I am facing some difficulties when attempting to create this following stored procedure, any kind of help is welcome:

create procedure checando(in nombrecillo varchar(30), in contrilla varchar(30), out resultado int)

begin 

if exists (select * from compas where nombre = nombrecillo and contrasenia = contrilla) then
    set resultado = 0;
else if exists (select * from compas where nombre = nombrecillo) then
    set resultado = -1;
else 
    set resultado = -2;
end if;
end;

The table which I am working on is:

+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| Nombre      | varchar(30) | YES  |     | NULL    |       |
| contrasenia | varchar(30) | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+

Any kind of help will be appreciated.

1 Answer

0 votes
by (12.7k points)

The issue is you either have not closed your if or you need an elseif:

create procedure checando(
    in nombrecillo varchar(30),
    in contrilla varchar(30), 
    out resultado int)
begin 

    if exists (select * from compas where nombre = nombrecillo and contrasenia = contrilla) then
        set resultado = 0;
    elseif exists (select * from compas where nombre = nombrecillo) then
        set resultado = -1;
    else 
        set resultado = -2;
    end if;
end;

Become a SQL expert with this complete SQL Training Course!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...