Ayuda con Sql.

21/11/2007 - 22:35 por jmauriciopb | Informe spam
Hola.
Tengo la siguiente tabla.

Periodo.iPeriodoId Int, iyyyy Int, imm Int
1 2006 1
2 2006 2
3 2006 3
4 2006 4
5 2006 5
6 2006 6
7 2006 7
8 2006 8
9 2006 9
10 2006 10
11 2006 11
12 2006 12
13 2007 1
14 2007 2
15 2007 3
16 2007 4
17 2007 5
18 2007 6
19 2007 7

Tengo el siguiente Sql.

Select *
From Periodo
Where iyyyy >= 2006
And imm >= 6
And iyyyy <= 2007
And imm <= 3

- No me da los resultados esperados.

Select *
From Nom_Periodo
Where CAST(iyyyy As VarChar(4)) + RIGHT('00' + CAST(imm As
VarChar(2)), 2) >= '200608'
And CAST(iyyyy As VarChar(4)) + RIGHT('00' + CAST(imm As
VarChar(2)), 2) <= '200702'

- Me da los resultados esperados.

Existe otro forma de hacerlo.

Saludos,
Mauricio Pulla.
Cuenca-Ecuador.
 

Leer las respuestas

#1 Alejandro Mesa
22/11/2007 - 00:01 | Informe spam
Trata:

Select *
from Periodo
where
iyyyy in (2006, 2007)
and
(
case
when iyyyy = 2006 and imm between 6 and 12 then 1
when iyyyy = 2007 and imm between 1 and 3 then 1
else 0
end
) = 1
go


AMB

"" wrote:

Hola.
Tengo la siguiente tabla.

Periodo.iPeriodoId Int, iyyyy Int, imm Int
1 2006 1
2 2006 2
3 2006 3
4 2006 4
5 2006 5
6 2006 6
7 2006 7
8 2006 8
9 2006 9
10 2006 10
11 2006 11
12 2006 12
13 2007 1
14 2007 2
15 2007 3
16 2007 4
17 2007 5
18 2007 6
19 2007 7

Tengo el siguiente Sql.

Select *
From Periodo
Where iyyyy >= 2006
And imm >= 6
And iyyyy <= 2007
And imm <= 3

- No me da los resultados esperados.

Select *
From Nom_Periodo
Where CAST(iyyyy As VarChar(4)) + RIGHT('00' + CAST(imm As
VarChar(2)), 2) >= '200608'
And CAST(iyyyy As VarChar(4)) + RIGHT('00' + CAST(imm As
VarChar(2)), 2) <= '200702'

- Me da los resultados esperados.

Existe otro forma de hacerlo.

Saludos,
Mauricio Pulla.
Cuenca-Ecuador.

Preguntas similares