29/07/2014, 11:09
|
| | Fecha de Ingreso: mayo-2013
Mensajes: 17
Antigüedad: 11 años, 9 meses Puntos: 0 | |
Respuesta: Comparando rangos de numeros Cita:
Iniciado por Libras
Código SQL:
Ver originalCREATE TABLE #temp ( id INT, tipo VARCHAR(20), inicio INT, fin INT ) INSERT INTO #temp VALUES (1,'tipo 1',300,600) INSERT INTO #temp VALUES (2,'tipo 1',800,900) INSERT INTO #temp VALUES (3,'tipo 1',950,970) DECLARE @inicio INT DECLARE @fin INT SET @inicio=240 SET @fin=250 IF ( SELECT COUNT(test) + COUNT(test2) FROM ( SELECT CASE WHEN @inicio BETWEEN inicio AND fin THEN 'si' ELSE 'no' END AS test, CASE WHEN @fin BETWEEN inicio AND fin THEN 'si' ELSE 'no' END AS test2 FROM #temp ) AS t1 WHERE test='si' OR test2='si')>=1 print 'Rango no disponible' ELSE 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 |