select
Publicado por keykoa (1 intervención) el 10/10/2008 13:14:03
Hola.
Tengo una tabla [@ITAPROYFASES] con varias columnas, algo como lo siguiente aunque con mas campos que no me interesan:
codigo | nombre | U_auxdate6 | U_auxdate11 | U_auxdate12
-------------------------------------------------------------------------------------------
xxxxxxx | xxxxxxxxx | xxxxxxxxxxxex | xxxxxxxxxxxxx | xxxxxxxxxxx
yyyyyyy | yyyyyyyyy | yyyyyyyyyyyyy | yyyyyyyyyyyyy | yyyyyyyyyyyy
zzzzzzz | zzzzzzzzz | zzzzzzzzzzzzz | zzzzzzzzzzzz | zzzzzzzzzzzz
quiero hacer una select que me muestre los campos de aquellas filas que tienen U_auxdate6 diferente a NULL o a '01/01/1900' y U_auxdate11 o U_auxdate12 o ambos como null o como '01/01/1900' que puesto en plan esquemita seria algo asi:
U_auxdate6 | U_auxdate11 | U_auxdate12
-------------------------------------------------------------------------------------------
21/02/2003 | 26/05/1999 |
05/16/2000 | | 12/06/2009
04/07/1998 | |
Para eso he escrito el siguiente código:
SELECT nombre, codigo,
(CASE (dbo.[@ITAPROYFASES].U_auxdate6) WHEN '1900-01-01 00:00:00.000' THEN NULL ELSE ([@ITAPROYFASES].U_auxdate6) END) as fecha0,
(CASE (dbo.[@ITAPROYFASES].U_auxdate11) WHEN '1900-01-01 00:00:00.000' THEN NULL ELSE (dbo.[@ITAPROYFASES].U_auxdate11) END) AS certificado,
(CASE (dbo.[@ITAPROYFASES].U_auxdate12) WHEN '1900-01-01 00:00:00.000' THEN NULL ELSE (dbo.[@ITAPROYFASES].U_auxdate12) END) AS encuesta
FROM [@ITAPROYFASES]
WHERE U_auxdate6 <> '1900-01-01' U_auxdate6 is not null
and
(((U_auxdate11 = '1900-01-01' OR U_auxdate11 IS NULL) AND
(U_auxdate12 = '1900-01-01' OR U_auxdate12 IS NULL)) OR
((U_auxdate11 = '1900-01-01' OR U_auxdate11 IS NULL) AND
(U_auxdate12 <> '1900-01-01' and U_auxdate12 IS NOT NULL)) OR
((U_auxdate11 <> '1900-01-01' and U_auxdate11 IS NOT NULL) AND
(U_auxdate12 = '1900-01-01' OR U_auxdate12 IS NULL)))
order by codigo
¿Pero no funciona, alguien sabe donde podria estar el error?
Muchas Gracias
Tengo una tabla [@ITAPROYFASES] con varias columnas, algo como lo siguiente aunque con mas campos que no me interesan:
codigo | nombre | U_auxdate6 | U_auxdate11 | U_auxdate12
-------------------------------------------------------------------------------------------
xxxxxxx | xxxxxxxxx | xxxxxxxxxxxex | xxxxxxxxxxxxx | xxxxxxxxxxx
yyyyyyy | yyyyyyyyy | yyyyyyyyyyyyy | yyyyyyyyyyyyy | yyyyyyyyyyyy
zzzzzzz | zzzzzzzzz | zzzzzzzzzzzzz | zzzzzzzzzzzz | zzzzzzzzzzzz
quiero hacer una select que me muestre los campos de aquellas filas que tienen U_auxdate6 diferente a NULL o a '01/01/1900' y U_auxdate11 o U_auxdate12 o ambos como null o como '01/01/1900' que puesto en plan esquemita seria algo asi:
U_auxdate6 | U_auxdate11 | U_auxdate12
-------------------------------------------------------------------------------------------
21/02/2003 | 26/05/1999 |
05/16/2000 | | 12/06/2009
04/07/1998 | |
Para eso he escrito el siguiente código:
SELECT nombre, codigo,
(CASE (dbo.[@ITAPROYFASES].U_auxdate6) WHEN '1900-01-01 00:00:00.000' THEN NULL ELSE ([@ITAPROYFASES].U_auxdate6) END) as fecha0,
(CASE (dbo.[@ITAPROYFASES].U_auxdate11) WHEN '1900-01-01 00:00:00.000' THEN NULL ELSE (dbo.[@ITAPROYFASES].U_auxdate11) END) AS certificado,
(CASE (dbo.[@ITAPROYFASES].U_auxdate12) WHEN '1900-01-01 00:00:00.000' THEN NULL ELSE (dbo.[@ITAPROYFASES].U_auxdate12) END) AS encuesta
FROM [@ITAPROYFASES]
WHERE U_auxdate6 <> '1900-01-01' U_auxdate6 is not null
and
(((U_auxdate11 = '1900-01-01' OR U_auxdate11 IS NULL) AND
(U_auxdate12 = '1900-01-01' OR U_auxdate12 IS NULL)) OR
((U_auxdate11 = '1900-01-01' OR U_auxdate11 IS NULL) AND
(U_auxdate12 <> '1900-01-01' and U_auxdate12 IS NOT NULL)) OR
((U_auxdate11 <> '1900-01-01' and U_auxdate11 IS NOT NULL) AND
(U_auxdate12 = '1900-01-01' OR U_auxdate12 IS NULL)))
order by codigo
¿Pero no funciona, alguien sabe donde podria estar el error?
Muchas Gracias
Valora esta pregunta


0