Código SQL:
podrian ayudarme please? Ver original
ALTER PROCEDURE [dbo].[Was2ReportHour] @Linea nvarchar(4), @Tubo nvarchar(1), @fecha datetime, @fechaend datetime, @hora nvarchar(4) AS BEGIN SELECT h.marca,h.target,P.CODOPTIMA, p.peso,p.vaso,p.fecha,o.linea,o.tubo INTO #checho3 FROM pesos AS p, optimas AS o,htargets AS h WHERE o.codigo = p.codOptima AND o.linea =@Linea AND o.tubo =@Tubo AND p.fecha >=@fecha AND p.fecha <@fechaend AND h.fecha >=@fecha AND h.fecha <@fechaend AND p.hora LIKE @hora AND h.codoptima = o.codigo AND h.hora LIKE @hora SELECT *,(SELECT COUNT(1)total FROM #checho3) AS totality FROM #checho3 ORDER BY fecha SELECT AVG(PESO)AS promedio FROM #checho3 DROP TABLE #checho3 END