- Local time
- Today, 09:40
- Joined
- Feb 19, 2002
- Messages
- 46,866
Please show me the two tables in the relationship window AND post the data in both tables. I have no idea what you are working from.
SELECT c.tx_clave, c.tx_descripcion, c.tx_grupo
FROM no_conceptos AS c
WHERE c.tx_clave In ('A01','A04','A07','A08','A10','A13','A16','A19','A22','A25','A84');
tx_clave tx_descripcion tx_grupo
A01 SUELDO MENSUAL 00
A04 PRIMA COMPLEMENTARIA 01
A07 BONO POR RESPONSABILIDAD (JEFATURA) 01
A08 PRIMA POR JEFATURA 01
A10 PRIMA POR HIJOS 03
A13 PRIMA DE PROFESIONALIZACION 01
A16 PRIMA POR ANTIGÜEDAD 01
A19 FERIADO 02
A22 BONO NOCTURNO 02
A25 BONO NOCTURNO JORNADA MIXTA 00
A84 APORTE IPSPUDO FAOV 02
SELECT g.tx_grupo, g.tx_descripcion, g.tx_claves
FROM no_grupos AS g;
tx_grupo tx_descripcion tx_claves
00 NO APLICABLE
01 SUELDO MENSUAL 'A01'
02 SUELDO INTEGRAL 'A01','A04','A07','A08','A10','A13','A16','A18','A19','A22'
03 APLICADO A LA PRIMA POR HIJOS
04 SUELDO AGREGADO. APLICADO A LA CUOTA IPSPUDO
05 CALCULO DEL BONO VACACIONAL/FIN DE AÑO 'A01','A04','A07','A08','A10','A13','A16','A19','A22','A25','A84'
SELECT c.tx_clave, c.tx_descripcion
FROM no_conceptos AS c, no_grupos as g
WHERE g.tx_grupo = '05' And instr(g.tx_claves, c.tx_clave) > 0;
I don't see how the OP can eliminate the InStr() without properly normalising the tables, and not having multiple values stuffed as a string in toThe entire point of the join was to eliminate the instr()
no_grupos.tx_claves
.With the example data shown, wouldn't that erroneously return the result of 'A18' forIf you do need the instr(), then you DON"T need the join and the group = 5
no_conceptos.tx_clave
which is present where tx_grupo
= 2 but not where tx_grupo
= 5Using a join would look more like:
SQL:SELECT c.tx_clave, c.tx_descripcion FROM no_conceptos AS c INNER JOIN no_grupos AS g ON g.tx_grupo = '05' AND InStr(g.tx_claves, c.tx_clave) > 0 ;
Yes, Thanks!. I just have to add parentesisI don't see how the OP can eliminate the InStr() without properly normalising the tables, and not having multiple values stuffed as a string in tono_grupos.tx_claves
.
With the example data shown, wouldn't that erroneously return the result of 'A18' forno_conceptos.tx_clave
which is present wheretx_grupo
= 2 but not wheretx_grupo
= 5
@pacctono , did the query with join in Post #16 not work?
SELECT
c.tx_clave,
c.tx_descripcion
FROM no_conceptos AS c
INNER JOIN no_grupos AS g
ON (g.tx_grupo = '05'
AND InStr(g.tx_claves, c.tx_clave) > 0)
;
The tables are almost normalized. You join to the group table on clave which would seem to bring back two rows, one from group 05 and one from group 02 But, then the criteria reduces the duplication to just the values from 05.I don't see how the OP can eliminate the InStr() without properly normalising the tables
How do you propose to do this without using InStr() (or some other, perhaps LIKE ?)You join to the group table on clave which would seem to bring back two rows
"A01" != "'A01','A04','A07','A08','A10','A13','A16','A19','A22','A25','A84'"
Can you give an example of the query you propose here in SQL? I'm being really dense and can't see how this would work.1. Join to the group table on clave and add criteria to select by group. This selects ALL claves that belong to a group WITHOUT the need to specify them in an instr.
Table no_grupos needs a child table for claves, rather than a single tx_claves field containing multiple comma-delimited values.The tables are almost normalized.
I posted a sample in #24. There is no point in beating this dead horse without the actual schema. If the OP wants to post it with some actual data, we can determine if the join will or will not work to eliminate the instr.Can you give an example of the query you propose here in SQL?
See Post #22If the OP wants to post it with some actual data
The schema is hopeless. The OP is lucky to get anything.See Post #22
On that, I think all participants in the thread agree!The schema is hopeless.