Ver Mensaje Individual
  #6 (permalink)  
Antiguo 29/07/2014, 11:09
erickplc16
 
Fecha de Ingreso: mayo-2013
Mensajes: 17
Antigüedad: 11 años
Puntos: 0
Respuesta: Comparando rangos de numeros

Cita:
Iniciado por Libras Ver Mensaje
Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. id INT,
  4. tipo VARCHAR(20),
  5. inicio INT,
  6. fin INT
  7. )
  8.  
  9.  
  10. INSERT INTO #temp VALUES (1,'tipo 1',300,600)
  11. INSERT INTO #temp VALUES (2,'tipo 1',800,900)
  12. INSERT INTO #temp VALUES (3,'tipo 1',950,970)
  13.  
  14.  
  15. DECLARE @inicio INT
  16. DECLARE @fin INT
  17. SET @inicio=240
  18. SET @fin=250
  19.  
  20. IF (
  21. SELECT COUNT(test) + COUNT(test2) FROM (
  22. SELECT CASE WHEN @inicio BETWEEN inicio AND fin THEN 'si' ELSE 'no' END AS test,
  23. CASE WHEN @fin BETWEEN inicio AND fin THEN 'si' ELSE 'no' END AS test2
  24. FROM #temp ) AS t1 WHERE test='si' OR test2='si')>=1
  25. print 'Rango no disponible'
  26. ELSE
  27.     INSERT INTO #temp VALUES (1,'tipo 1',@inicio,@fin)

Con algo como eso obtienes lo que necesitas :)
muchas gracias, justamente lo que necesitaba. disculpa que hasta ahora pero estaba revisando otras consultas.

Saludos