[BlackTDN] :: Identificando as marcações ímpares na tabela SP8
Autor: иαldσ dj | Publicado: 2017-08-10T10:04:00-03:00



1)&nbsp;A consulta das marcações impares;

2) A "deleção lógica" dos registros impares;



Segue:



1) Para consultar as marcações impares:




------------------------------------------------------------------------------------------------
SELECT SP8.P8_FILIAL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_MAT
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_PAPONTA
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_ORDEM
&nbsp; FROM SP8010 SP8
WHERE SP8.D_E_L_E_T_=' '
GROUP BY SP8.P8_FILIAL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_MAT
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_PAPONTA
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_ORDEM
HAVING ((COUNT(*)%2)=1)
ORDER BY 1,2,3,4

------------------------------------------------------------------------------------------------


2) Para a "Deleção Lógica" das marcações impares:



UPDATE SP8_U
&nbsp;&nbsp;&nbsp; SET SP8_U.D_E_L_E_T_='*'
FROM
&nbsp; SP8010 SP8_U
&nbsp; INNER JOIN
&nbsp; (
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT SP8.P8_FILIAL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_MAT
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_PAPONTA
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_ORDEM
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM SP8010 SP8
&nbsp;&nbsp;&nbsp; WHERE SP8.D_E_L_E_T_=' '
&nbsp;&nbsp;&nbsp; GROUP BY SP8.P8_FILIAL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_MAT
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_PAPONTA
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_ORDEM
&nbsp;&nbsp;&nbsp; HAVING ((COUNT(*)%2)=1)
&nbsp;&nbsp; ) SP8_R
&nbsp;&nbsp; ON&nbsp; SP8_U.P8_FILIAL=SP8_R.P8_FILIAL
&nbsp; AND SP8_U.P8_MAT=SP8_R.P8_MAT
&nbsp; AND SP8_U.P8_PAPONTA=SP8_R.P8_PAPONTA
&nbsp; AND SP8_U.P8_ORDEM=SP8_R.P8_ORDEM
WHERE SP8_U.D_E_L_E_T_=' '&nbsp;



OU

------------------------------------------------------------------------------------------------
MERGE INTO
&nbsp; SP8010 SP8_U
USING
&nbsp; (
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT SP8.P8_FILIAL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_MAT
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_PAPONTA
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_ORDEM
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM SP8010 SP8
&nbsp;&nbsp;&nbsp; WHERE SP8.D_E_L_E_T_=' '
&nbsp;&nbsp;&nbsp; GROUP BY SP8.P8_FILIAL
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_MAT
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_PAPONTA
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,SP8.P8_ORDEM
&nbsp;&nbsp;&nbsp; HAVING ((COUNT(*)%2)=1)
&nbsp; ) SP8_R
ON&nbsp; SP8_U.P8_FILIAL=SP8_R.P8_FILIAL
AND SP8_U.P8_MAT=SP8_R.P8_MAT
AND SP8_U.P8_PAPONTA=SP8_R.P8_PAPONTA
AND SP8_U.P8_ORDEM=SP8_R.P8_ORDEM
WHEN MATCHED THEN
&nbsp; UPDATE SET
&nbsp;&nbsp;&nbsp; SP8_U.D_E_L_E_T_='*';




------------------------------------------------------------------------------------------------


Obs.: 



1) Antes de efetuar qualquer operação que modifique os dados diretamente no SGBD efetue uma cópia da tabela;



2) Nem sempre os registros devem ser deletados. A melhor opção é identificar os funcionários com marcações impares e incluir a marcação faltante.