1
The figure shows that there are several lines for the same product.
The solution varies according to the version of SQL Server. Considering getting the latest information from a single product, we can have:
-- código #2
with Produto_ord as (
SELECT ID_PRODUTOEMPRESA, DT_DATA, VR_PRECO,
seq= row_number() over (order by DT_DATA desc)
from tabela
where ID_PRODUTOEMPRESA = ___
)
SELECT ID_PRODUTOEMPRESA, DT_DATA, VR_PRECO
from Produto_ord
where seq = 1;
Is your column varchar? The result you expect is the date 12/03/2018?
– Marconi
Try something like this man: <b>select top 1 vr_preco from table Where dt_data = (select max(dt_data) from table)</b>. Note: I am considering that the field dt_data is date.
– Carlos Mesquita Aguiar
What is the version of SQL Server?
– José Diz
Version 2017....
– Master JR