Con esto ya debe quedar.
Código SQL:
Ver originalSELECT h.hora,h.marca,h.codoptima AS codoptimaT,h.target,P.CODOPTIMA,O.CODIGO,
p.hora,p.peso,p.vaso,p.fecha,o.linea,o.tubo
INTO #temp
FROM pesos AS p, optimas AS o,htargets AS h
WHERE o.codigo = p.codOptima AND o.linea = 'L01S'
AND o.tubo LIKE '%' AND p.fecha BETWEEN '2010-06-18 09:00' AND '2010-06-18 09:30'
AND p.hora='9:00 - 9:30' AND h.codoptima = o.codigo AND h.hora='9:00 - 9:30'
SELECT *,(SELECT COUNT(1)total FROM #temp) FROM #temp