Hola flaviovich, MUCHAS GRACIAS!! me ha funcionado.
http://ompldr.org/vNzFzdA
de verdad agradezco tu desinteresada ayuda y el apoyo!
Código SQL:
Ver originalALTER PROCEDURE [dbo].[monitor3]
@fecha datetime,
@linea nvarchar(5),
@hora nvarchar(15) AS
--declare @reg int
BEGIN
SET Nocount ON
DECLARE @reg INT
SELECT @reg = COUNT(1)
FROM optimas AS o
INNER JOIN pesos AS p ON o.codigo = p.codoptima
INNER JOIN htargets AS h ON o.codigo = h.codoptima
WHERE o.linea = @linea
AND p.fecha >= @fecha AND h.fecha >= @fecha
AND p.hora = @hora AND h.hora = @hora
SELECT top 1 h.hora AS hora1,h.marca,h.target,h.fecha AS hfecha,p.hora,p.peso,p.fecha,o.linea,@reg AS 'RowsReturned'
FROM optimas AS o
INNER JOIN pesos AS p ON o.codigo = p.codoptima
INNER JOIN htargets AS h ON o.codigo = h.codoptima
WHERE o.linea = @linea
AND p.fecha >= @fecha AND h.fecha >= @fecha
AND p.hora = @hora AND h.hora = @hora
END