Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/01/2012, 03:30
eloy_ameneiros
 
Fecha de Ingreso: julio-2010
Mensajes: 93
Antigüedad: 13 años, 9 meses
Puntos: 0
Varias condiciones en where SQL Server 2008

Buenos días,

resulta que tengo el siguiente problema:

Tengo una tabla como la siguiente

telefono cum mes tipo
999999999 sndiciembre01 Diciembre2011 Orange
888888888 snenero01 Enero2012 Orange

Lo que necesito es poder seleccionar en base al tipo, los meses que yo quiero, es decir:

if (tipo = Orange)

mes != Diciembre2011
mes != Enero2012
.
.
.

Todo esto dentro del where. Actualmente tengo así la consulta:


SELECT DISTINCT DF.Telefono, DF.Telefono2, DF.Archivo, DF.Tipo, O.Descripcion AS Operador, DF.Fecha, E.Descripcion AS Especial,
DF.Registro_nuevo, DP.Nomtitular, DP.Apellido1, DP.Apellido2, DC.Calle, DC.Num, DC.CP, DC.Poblacion, P.Descripcion AS Provincia,
RO3.Cobertura AS Cobertura_Orange
FROM DIRINFO DF
INNER JOIN DATOS_PERSONALES DP
ON DF.Telefono = DP.Telefono
INNER JOIN DIRECCION DC
ON DF.Telefono = DC.Telefono
INNER JOIN PROVINCIAS P
ON DC.Provincia = P.Uid
INNER JOIN OPERADOR O
ON DF.Operador = O.Uid
INNER JOIN ESPECIAL E
ON DF.Especial = E.Uid
INNER JOIN RANGO_ORANGE_3 RO3
ON DF.Telefono = RO3.Telefono
LEFT JOIN RJ_SCORING_ALTO RSA
ON DF.Telefono = RSA.Telefono
LEFT JOIN AGENDAS A
ON DF.Telefono = A.Telefono
LEFT JOIN TRAMITACIONES T
ON DF.Telefono = T.Telefono
LEFT JOIN CAMPAÑAS_ULTIMOS_MESES CUM
ON DF.Telefono = CUM.Telefono
WHERE (E.Descripcion = 'ACTUALIZACION-DIC2010' )
AND (P.Descripcion = 'BALEARES' )
AND (DF.Tipo = 'R')
AND (O.Descripcion LIKE '%TELEFÓNICA%')
AND (RO3.Cobertura = 'ULL'
OR RO3.Cobertura = 'FUTURIBLE' )
AND (DF.Robinson IS NULL)
AND (RSA.Telefono IS NULL)
AND (A.Telefono IS NULL)
AND (T.Telefono IS NULL)
AND (DP.Apellido1 IS NOT NULL)
AND (DP.Apellido2 IS NOT NULL)
AND (CUM.Tipo != 'Orange')
/*AND (CUM.Mes != 'Diciembre2011'
AND CUM.Mes != 'Noviembre2011'
AND CUM.Mes != 'Octubre2011'
AND CUM.Mes != 'Septiembre2011' */

OR CUM.Mes IS NULL
OR CUM.Tipo IS NULL)

Lo marcado es donde necesito poder hacer esa selección.

Os agradecería si me pudieseis echar una mano.

Un saludo,

Eloy