-2
There is possibility to create a table of CAIXA
that, for example, when placing the CODIGO
of the product, pull the DESCRIÇÃO
automatic, being in the table of PRODUTOS
??
-2
There is possibility to create a table of CAIXA
that, for example, when placing the CODIGO
of the product, pull the DESCRIÇÃO
automatic, being in the table of PRODUTOS
??
1
One way to achieve this is by using a Computed Column with a function, and this function will perform a select
on the table Produtos
Example:
CREATE FUNCTION dbo.getDescricaoProduto(@produtoID int)
RETURNS varchar(50)
AS
BEGIN
DECLARE @retorno varchar(50)
set @retorno =(Select Descricao from Produtos where ProdutoId = @produtoID)
RETURN @retorno
END
ALTER TABLE dbo.Caixa ADD
ProdutoDescricao AS dbo.getDescricaoProduto(ProdutoId)
GO
See answer on Soen: https://stackoverflow.com/questions/6867047/sql-server-computed-column-select-from-another-table
Browser other questions tagged sql sql-server
You are not signed in. Login or sign up in order to post.
You want to avoid joins?
– rray
You can do joins
– Daniel Saraiva
Depending on the context you can create a view to simplify certain queries, and of course you will need joins in its implementation.
– rray