Skip to main content
4 de 8
removido código #2
José Dız
  • 7mil
  • 2
  • 18
  • 30

Avalie

-- código #1
declare @Hoje date;
set @Hoje= cast(current_timestamp as date);

--
SELECT P.Id, P.Name, 
       (SELECT T.Name
          from Types as T
          where T.Id = P.Tipo) as Tipo, 
       (SELECT top (1) Preco 
          from Lot as L1 
          where L1.ProdutoId = P.Id
                and L1.Fim is NULL
                and @Hoje >= L1.Inicio 
          order by L1.Inicio desc) as [Preço oficial hoje],
       (SELECT Preco 
          from Lot as L2 
          where L2.ProdutoId = P.Id
                and @Hoje between L2.Inicio and L2.Fim) as [Preço oferta hoje]
  from Products as P;
José Dız
  • 7mil
  • 2
  • 18
  • 30