1
I am creating a small database on SQL Server, for an ASP.NET mvc project of my course.
Using ADO.NET I am creating procedures, to use in my DAL class, so far everything well has a lot of information about and everything else, however, what I need to do is to perform a Join within a previous, I haven’t found anything about or at least anything I’ve understood how it works.
The problem is that I am not understanding how to put the parameters of the two tables in my previous to perform the select with Inner Join.
I tried this way:
CREATE TABLE PRODUTO(
ID_PRATO INTEGER PRIMARY KEY IDENTITY,
FK_CATEGORIA_ID INT,
DESCRICAO_PRATO VARCHAR(200),
VALOR DECIMAL(5,2) NOT NULL,
CONSTRAINT FK_CATEGORIA_ID FOREIGN KEY (FK_CATEGORIA_ID) REFERENCES CATEGORIA (ID_CATEGORIA)
)
GO
CREATE TABLE ENTREGA(
ID_ENTREGA INTEGER PRIMARY KEY IDENTITY,
FK_PRATO_ID2 INT,
CONSTRAINT FK_PRATO_ID2 FOREIGN KEY (FK_PRATO_ID2) REFERENCES PRODUTO (ID_PRATO),
STATUS_ENTREGA VARCHAR(10) CHECK (STATUS_ENTREGA IN ('CANCELADA','TRANSITO','REALIZADA'))
)
GO
create procedure sp_select_produto
(
@id_prato int,
@descricao_cat varchar(200),
@descricao_prato varchar(200),
@valor decimal(5,2)
)
as
select prod.id_prato,cat.descricao_cat,prod.descricao_prato,prod.valor from CATEGORIA
as cat inner join PRODUTO prod
on cat.id_categoria=prod.FK_CATEGORIA_ID
where prod.id_prato=ID_PRATO
return
But when I give an exec an error appears:
Mensagem 201, Nível 16, Estado 4, Procedimento sp_select_produto, Linha 225 O procedimento ou a função 'sp_select_produto' espera o parâmetro '@id_prato', que não foi fornecido.
Any idea what I can do in this case ?
Simply on your call from
procedure
(that you did not show in your question) there is no passage to the parameterid_prato
.– Sorack
At the moment, I’m not performing the call in the project I was trying to test within sql server manager only, but I understood what you said I will perform more tests thank you
– Nelson Francisco