Ayuda!!!Busquedas mayor en varchar

22/08/2006 - 18:56 por Pao | Informe spam
Hola a todos, tengo un sp dentro del cual hay una variable del tipo varchar y
veo que le hacen busquedades de este tipo >= o > es optimo usar esto:

Datos
name
rows reserved
data index_size unused

deudores
2526634 1111888 KB
594512 KB 517248 KB 128 KB


La tabla (Estructura de tabla)
Name
Owner

Type Created_datetime

-

deudores
dbo

user table 2006-08-15
15:55:55.333



Column_name
Type

Computed Length Prec
Scale Nullable TrimTrailingBlanks
FixedLenNullInSource Collation


de_fecha
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_tipoid
char

no 2
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_codigoid
char

no 13
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_nombre
char

no 60
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_cartera_vencer
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_contigentes_vencer
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_nodevenga_interes
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_91_180
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_181_1
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_1_3
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_mas_3
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_demanda_judicial
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_cartera_castigada
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_garantia
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_demanda
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_castigado
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_calificacion_a
char

no 2
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_calificacion_b
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_calificacion_c
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_calificacion_d
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_calificacion_e
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_triesgo
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_60_90
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_tarjeta
char

no 1
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_institucion
char

no 60
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_nuevo
smallint

no 2 5
0 yes (n/a)
(n/a) NULL
de_monto_30_60
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_tiporiesgo
char

no 1
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_tipocredito
char

no 1
yes yes
yes SQL_Latin1_General_CP1_CI_AS



sp_helpindex deudores
index_name
index_description


index_keys




-
i_codigo
nonclustered located on
PRIMARY

de_codigoid
i_de_codigoid
nonclustered located on
PRIMARY

de_fecha, de_codigoid
i_de_nombre
nonclustered located on
PRIMARY

de_fecha, de_nombre
i_de_triesgo
nonclustered located on
PRIMARY

de_fecha, de_triesgo
i_fecha
nonclustered located on
PRIMARY

de_fecha
idx_tesofi
nonclustered located on
PRIMARY

de_codigoid, de_tiporiesgo, de_tipocredito






create procedure sp_consulta_cliente5 ( @idtran varchar(2) = null,
@idtipo varchar(1) = null,
@idaccion varchar(1) = null,
@idcedula varchar(13) = null,
@idnombre varchar(40) = null )
as
declare
@w_fecha_max int /*Fecha Maxima Cargada en la Tabla */


/* Consulta General de Clientes */

if @idtran="CG"
begin

/* Verifica la Fecha Maxima Cargada en la Tabla */

select @w_fecha_max = max(de_fecha) from deudores (index =
i_de_codigoid)

set rowcount 20
if @idtipo="0"
begin
if @idaccion = "R" /* Por Cedula */
select * from deudores (index = i_de_codigoid) where de_fecha = 199908
and de_codigoid >= @idcedula

if @idaccion = "N" /* Por Apellido */
select * from deudores (index = i_de_nombre) where de_fecha =
@w_fecha_max and de_nombre >= @idnombre
end
else
if @idtipo="1"
begin
if @idaccion = "R" /* Por Cedula */
select * from deudores (index = i_de_codigoid) where de_fecha =
@w_fecha_max and de_codigoid > @idcedula

if @idaccion = "N" /* Por Apellido */
select * from deudores (index = i_de_nombre) where de_fecha =
@w_fecha_max and de_nombre > @idnombre
end
end

GO
 

Leer las respuestas

#1 Maxi
22/08/2006 - 19:20 | Informe spam
Hola Pao, la verdad que no se ve mucho :( te recomiendo compilar la
informacion y ponerla en un txt


Salu2

Microsoft MVP SQL Server
Culminis Speaker
INETA Speaker

"Pao" escribió en el mensaje
news:
Hola a todos, tengo un sp dentro del cual hay una variable del tipo
varchar y
veo que le hacen busquedades de este tipo >= o > es optimo usar esto:

Datos
name
rows reserved
data index_size unused

deudores
2526634 1111888 KB
594512 KB 517248 KB 128 KB


La tabla (Estructura de tabla)
Name
Owner

Type Created_datetime

-

deudores
dbo

user table 2006-08-15
15:55:55.333



Column_name
Type

Computed Length
Prec
Scale Nullable TrimTrailingBlanks
FixedLenNullInSource Collation


de_fecha
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_tipoid
char

no 2
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_codigoid
char

no 13
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_nombre
char

no 60
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_cartera_vencer
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_contigentes_vencer
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_nodevenga_interes
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_91_180
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_181_1
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_1_3
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_mas_3
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_demanda_judicial
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_cartera_castigada
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_garantia
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_demanda
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_castigado
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_calificacion_a
char

no 2
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_calificacion_b
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_calificacion_c
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_calificacion_d
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_calificacion_e
int

no 4 10
0 yes (n/a)
(n/a) NULL
de_triesgo
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_monto_60_90
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_tarjeta
char

no 1
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_institucion
char

no 60
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_nuevo
smallint

no 2 5
0 yes (n/a)
(n/a) NULL
de_monto_30_60
real

no 4 24
NULL yes (n/a)
(n/a) NULL
de_tiporiesgo
char

no 1
yes yes
yes SQL_Latin1_General_CP1_CI_AS
de_tipocredito
char

no 1
yes yes
yes SQL_Latin1_General_CP1_CI_AS



sp_helpindex deudores
index_name
index_description


index_keys




-
i_codigo
nonclustered located on
PRIMARY

de_codigoid
i_de_codigoid
nonclustered located on
PRIMARY

de_fecha, de_codigoid
i_de_nombre
nonclustered located on
PRIMARY

de_fecha, de_nombre
i_de_triesgo
nonclustered located on
PRIMARY

de_fecha, de_triesgo
i_fecha
nonclustered located on
PRIMARY

de_fecha
idx_tesofi
nonclustered located on
PRIMARY

de_codigoid, de_tiporiesgo, de_tipocredito






create procedure sp_consulta_cliente5 ( @idtran varchar(2) = null,
@idtipo varchar(1) = null,
@idaccion varchar(1) = null,
@idcedula varchar(13) = null,
@idnombre varchar(40) = null )
as
declare
@w_fecha_max int /*Fecha Maxima Cargada en la Tabla */


/* Consulta General de Clientes */

if @idtran="CG"
begin

/* Verifica la Fecha Maxima Cargada en la Tabla */

select @w_fecha_max = max(de_fecha) from deudores (index > i_de_codigoid)

set rowcount 20
if @idtipo="0"
begin
if @idaccion = "R" /* Por Cedula */
select * from deudores (index = i_de_codigoid) where de_fecha = 199908
and de_codigoid >= @idcedula

if @idaccion = "N" /* Por Apellido */
select * from deudores (index = i_de_nombre) where de_fecha > @w_fecha_max and de_nombre >= @idnombre
end
else
if @idtipo="1"
begin
if @idaccion = "R" /* Por Cedula */
select * from deudores (index = i_de_codigoid) where de_fecha > @w_fecha_max and de_codigoid > @idcedula

if @idaccion = "N" /* Por Apellido */
select * from deudores (index = i_de_nombre) where de_fecha > @w_fecha_max and de_nombre > @idnombre
end
end

GO

Preguntas similares