FoxPro/Visual FoxPro - FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

 
Vista:
Imágen de perfil de HELDER MARTINEZ

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por HELDER MARTINEZ (37 intervenciones) el 08/01/2016 16:12:57
HOLA A TODOS, FELIZ AÑO NUEVO.

TENGO DOS TABLAS LLAMADAS;

TBLPACIENTES:
CODIGO_PAC
NOMBRES
APELLIDOS
IDENTIDAD


TBLANTECEDENTE:
CODIGO_PAC_ANT
DESCRIPION
FECHA


QUIERO HACER UNA BUSQUEDA O FILTRO POR MEDIO DE ESTOS 4 CAMPOS:
CODIGO_PAC NOMBRES APELLIDOS IDENTIDAD

HAGO LA BUSQUEDA BIEN POR MEDIO DEL CAMPO QUE ESTA RELACIONADO CODIGO_PAC Y CODIGO_PAC_ANT PORQUE AMBOS CAMPOS TIENEN IGUAL VALORES.

EL CODIGO_PAC SE ALMACENA EN LA TABLA TBLANTECEDENTE EL MISMO VALOR EN EL CAMPO CODIGO_PAC_ANT

LA BUSQUEDA CON EL CAMPO CODIGO_PAC_ANT,

************************************************************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PUBLIC cBuscarAnt, nBuscarAnt1
cBuscarAnt = ALLTRIM(this.Value)
nBuscarAnt1 = thisform.pgFcSiMP.pg2AntePato.opgBuscarAnt.Value
 
**buscando
IF nBuscarAnt1 =  1
SELECT tblantepato
SET FILTER TO
SET FILTER TO ALLTRIM(cBuscarAnt)$ALLTRIM(codigo_pac_ant)
GO TOP
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.RecordSource = "tblantepato"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column1.ControlSource = "tblantepato.codigo_ant"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column2.ControlSource = "tblantepato.fecha_ant"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column3.ControlSource = "tblantepato.descrip_ant"
ENDIF

***********************************************

AHORA CUANDO QUIERO HACER LA BUSQUEDA POR MEDIO DE NOMBRES, APELLIDOS, IDENTIDAD NO ME FILTRA, SE QUE EL CAMPO NOMBRES NO EXISTE EN LA SEGUNDA TABLA, PERO PODRIA HACER UN FILTRO POR MEDIO DE CODIGO_PAC_ANT A LA TABLA PRIMARIA.

COMO PODRIA HACER?

SALUDOS,
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 1.011
Oro
Ha mantenido su posición en FoxPro/Visual FoxPro (en relación al último mes)
Gráfica de FoxPro/Visual FoxPro

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por Fidel José (657 intervenciones) el 08/01/2016 21:12:50
En tu ejemplo el nombre de la tabla no se corresponde con el modelo que presentas: (antepato o antecedente?) y los campos no tienen el mismo nombre.

1) Si el código que pones en CODIGO_PAC es el mismo código que pones en CODIGO_PAC_ANT, los campos deben tener el mismo nombre: CODIGO_PAC

2) Olvídate de SET FILTER. La única conclusión a la que puedes llegar es que solamente sirve para pequeñas tablas locales.

3) Para tu caso, la búsqueda por CODIGO_PAC, NOMBRES, APELLIDOS, IDENTIDAD debe hacerse siempre en la tabla primaria TBLPACIENTES, con los métodos que quieras (INDEXSEEK() si tienes índices sobre codigo_pac, etc., LOCATE, SELECT - SQL.
Una vez que consigues el registro de la tabla de pacientes, puedes traerte el historial

SELECT DESCRIP FROM TBLANTEPATO WHERE CODIGO_PAC = lcCodigoObtenido INTO CURSOR curAntecedentes
if _tally = 0
Messagebox("No hay antecedentes")
else
* Mostrar Resultado
endif
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de HELDER MARTINEZ

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por HELDER MARTINEZ (37 intervenciones) el 09/01/2016 05:38:20
SI GRACIAS FIDEL,

LOS CAMPOS PARA

TBLPACIENTES:
codigo_pac
id_pac
nombres_pac
apellidos_pac

TBLANTEPATO
codigo_pac_ant
descrip_ant
fecha_ant

AHORA EL RESULTADO ENCONTRADO EN ESA BUSQUEDA QUIERO QUE ME MUESTRE EN UN GRID LO DE LA TABLA TBLANTEPATO:

thisform.pgFcSiMP.pg2AntePato.grdTblantepato.RecordSource = "tblantepato"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column1.ControlSource = "tblantepato.codigo_ant"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column2.ControlSource = "tblantepato.fecha_ant"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column3.ControlSource = "tblantepato.descrip_ant"

TENDRIA QUE USAR EL SQL curAntecedentes PARA DESPLEGAR DATOS EN GRID O LA TABLA TBLANTEPATO?

SALUDOS,
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de HELDER MARTINEZ

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por HELDER MARTINEZ (37 intervenciones) el 09/01/2016 05:57:18
PROBE DE ESTA FORMA, COMO TU ME INDICAS, PERO NO ME DA LOS RESULTADOS ESPERADOS;

PUBLIC nCodPacAnt1, nID
nCodPacAnt1 = ALLTRIM(thisform.pgFcSiMP.pg2AntePato.txtCodigo_pac_ant.Value)
nID = ALLTRIM(this.Value)

SELECT tblPacientes
LOCATE FOR ALLTRIM(nID) = ALLTRIM(id_pac)
IF FOUND()
thisform.pgFcSiMP.pg2AntePato.TXTCOdigo_pac_ant.Value = ALLTRIM(codigo_pac)
thisform.pgFcSiMP.pg2AntePato.txtNombres_pac_ant.Value = ALLTRIM(nombres_pac)
thisform.pgFcSiMP.pg2AntePato.txtApellidos_pac_ant.Value = ALLTRIM(apellidos_pac)
ENDIF

SELECT codigo_ant, fecha_ant, descrip_ant FROM tblantepato WHERE codigo_pac_ant = nCodPacAnt1 INTO CURSOR _tblantepato

thisform.pgFcSiMP.pg2AntePato.grdTblantepato.RecordSource = "_tblantepato"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column1.ControlSource = "_tblantepato.codigo_ant"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column2.ControlSource = "_tblantepato.fecha_ant"
thisform.pgFcSiMP.pg2AntePato.grdTblantepato.column3.ControlSource = "_tblantepato.descrip_ant"

BROWSE
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 1.011
Oro
Ha mantenido su posición en FoxPro/Visual FoxPro (en relación al último mes)
Gráfica de FoxPro/Visual FoxPro

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por Fidel José (657 intervenciones) el 09/01/2016 15:51:51
No termino de entender cuál es tu campo clave: ID_PAC, CODIGO_PAC, CODIGO_PAC_ANT ???
Es un numérico o es alfanumérico?

Si es un numérico, te conviene definir en el Init del form o en el diseñador:
thisform.pgFcSiMP.pg2AntePato.txtCodigo_pac_ant.Value = 0
Con esto, tomará solamente valores numéricos y no necesitarás transformar nada.

Qué buscaría esto?
nID = ALLTRIM(this.Value) && supongo que está en el Valid o en el Lostfocus de un textbox
SELECT tblPacientes
LOCATE FOR ALLTRIM(nID) = ALLTRIM(id_pac) && ID_PAC ???

Si CODIGO_PAC (o como se llame) no es un numérico, debería completarse con los ceros a la izquierda del campo para evitar confusiones. Mientras tanto, en el select tendrás que usar el comparador exacto : ALLTRIM(CODIGO_PAC_ANT) == cCodigoBuscado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por neo (1604 intervenciones) el 10/01/2016 03:52:03
inner join fue la solucion..

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de HELDER MARTINEZ

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por HELDER MARTINEZ (37 intervenciones) el 10/01/2016 06:33:48
NEO, FUE FANTASTICO Y ESPECTACULAR COMO FUNCIONA, SOLO QUEDA HACER REFERENCIA A LA TABLA DBS A TRAVES DEL CURSOR SQL.

MUCHAS GRACIAS,
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de HELDER MARTINEZ

FILTRAR 2 TABLAS QUE TIENE UN CAMPO CLAVE IGUAL

Publicado por HELDER MARTINEZ (37 intervenciones) el 10/01/2016 06:31:05
MUCHAS GRACIAS FIDEL JOSE , ME SIRVIO MUCHO TU APORTE.

SALUDOS,
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar