Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help with a subquery

Author  Topic 

jpatracar
Starting Member

11 Posts

Posted - 2008-01-30 : 14:18:55
Hello all,
I've been trying to evaluate a subquery, but I'm not being able to do so.

In this subquery what I get is the final destination, i obtain this point by column named intPunto
Here's where i get stucked:
In order to show these points there is one rule:
the column named intId_Tipo must be <> 6
There are some of these points referenced with this type, so i want to ingnore them because I do not need to show them.
In some cases the final destination would be for example:
2+1 which is 3..but the record referenced to this point is type 6, so the value obtained in the subquery is NULL.

What I want to do in this case is to increase the intPunto (2+(1+1))
in order to retrieve the name of that intPunto and show it in the select.
This is the query that I have


SELECT h.dt_Lectura, h.int_Velocidad, rp.int_VelMaxima,
rp.intPunto, rp.strDescripcion_Punto,

(SELECT strDescripcion_Punto FROM tblRecorrido_Puntos WHERE intPunto = (rp.intPunto + 1) AND rp.intId_Ruta_Ramal =intId_Ruta_Ramal AND intId_Tipo <>6
),

(SELECT COUNT(intPunto) from tblRecorrido_Puntos WHERE intPunto = rp.intPunto AND rp.intId_Ruta_Ramal =intId_Ruta_Ramal) AS ContadorPuntos,
a.idRuta_Guid, a.idRamal_Guid,a.idUnidad_Guid, a.idOperador_Guid

FROM tblHistorico h

INNER JOIN tblAsignaciones a
ON a.id=h.intIdAsignaciones

INNER JOIN tblRutaRamal_Generado rrg
ON rrg.id_Ruta = a.intRuta_Asignada

INNER JOIN tblRecorrido_Puntos rp
ON (rp.intId_Ruta_Ramal =rrg.intId_Ruta_Ramal AND rp.intPunto=h.int_PtoDest)


WHERE (
rp.intId_Tipo <> 6
)

ORDER BY rp.intPunto



What do I need to do in order to evaluate this special case when the intPunto +1 give me a null value and I want to increase it again?

Thanks for your help and time
Jaime,
   

- Advertisement -