
SELECT TB02111_CODIGO,* FROM TB02111 --ORDER BY 1
WHERE TB02111_SITUACAO = 'A'
AND TB02111_CODIGO = '2214'
--CAST(TB02111_DTCAD AS DATE) = CAST(GETDATE() AS DATE) 
ORDER BY 1

SELECT TB02112_CODIGO, TB02112_PAT,* FROM TB02112 
WHERE TB02112_SITUACAO = 'A'
--AND TB02112_CODIGO = '1678'
--AND TB02112_PAT IN ('027307','027160')
--AND CAST(TB02112_DTCAD AS DATE) = CAST(GETDATE() AS DATE)
ORDER BY 1


--SELECT TB02111_CODIGO,TB02111_NOME,* FROM TB02111 WHERE  CAST(TB02111_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

--SELECT TB02112_CODIGO, TB02112_PAT,* FROM TB02112 WHERE CAST(TB02112_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

SELECT TB02054_PAT,* FROM TB02054 WHERE TB02054_QTPROD > TB02054_QTPRODS 
 --AND TB02054_PAT IN ('026385','026383')


--teste estradas

 SELECT * FROM TB02111 WHERE CAST(TB02111_DTCAD AS DATE) = CAST(GETDATE() AS DATE) ORDER BY TB02111_DTCAD DESC
 SELECT * FROM TB02112 WHERE CAST(TB02112_DTALT AS DATE) = CAST(GETDATE() AS DATE) ORDER BY TB02112_DTCAD DESC

 SELECT * FROM TB02018 WHERE  CAST(TB02018_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

 SELECT * FROM TB02019 WHERE  CAST(TB02019_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

 SELECT * FROM TB02030 WHERE  CAST(TB02030_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

 SELECT * FROM TB02031 WHERE  CAST(TB02031_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

 SELECT * FROM TB02114 WHERE  CAST(TB02114_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

 SELECT * FROM TB02113 WHERE  CAST(TB02113_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

-- SELECT * FROM TB02176 WHERE CAST(TB02176_DTALT AS DATE) = CAST(GETDATE() AS DATE)

 --SELECT * FROM SUBS_CONTRATO_ACESSORIOS

 SELECT * FROM SUBS_CONTRATO








DELETE FROM TB02019  WHERE  CAST(TB02019_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

DELETE FROM TB02018 WHERE  CAST(TB02018_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

DELETE FROM TB02031 WHERE  CAST(TB02031_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

DELETE FROM TB02030 WHERE  CAST(TB02030_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

DELETE FROM TB02114 WHERE CAST(TB02114_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

DELETE FROM TB02113 WHERE  CAST(TB02113_DTCAD AS DATE) = CAST(GETDATE() AS DATE)

DELETE FROM TB02176 WHERE CAST(TB02176_DTALT AS DATE) = CAST(GETDATE() AS DATE)

DELETE FROM SUBS_CONTRATO_ACESSORIOS

DELETE  FROM SUBS_CONTRATO

DELETE FROM TB02208

DELETE FROM TB02112 WHERE CAST(TB02112_DTCAD AS DATE) = CAST(GETDATE() AS DATE)
DELETE FROM TB02111 WHERE CAST(TB02111_DTCAD AS DATE) = CAST(GETDATE() AS DATE)






SELECT * FROM TB02208

SELECT * FROM TB02113 WHERE CAST(TB02113_DTCAD AS DATE) = CAST(GETDATE() AS DATE)


SELECT TB02112_GRUPO, TB02112_PAT,TB02112_CODSITE,* FROM TB02112
WHERE CAST(TB02112_DTCAD AS DATE) = CAST(GETDATE() AS DATE)


SELECT TB02112_CODIGO, TB02112_PAT, TB02114_NUMSERIE, TB02114_PRODUTO, TB02112_NUMSERIE FROM TB02112 
LEFT JOIN TB02114 ON TB02114_NUMSERIE = TB02112_NUMSERIE
WHERE TB02114_NUMSERIE IS NOT NULL
AND TB02112_SITUACAO = 'A'
AND TB02114_NUMSERIE = 'BRJ111J35Y' 


SELECT * FROM TB02114
WHERE TB02114_NUMSERIE = 'SPE05DZXB'










SELECT 
	TB02114_ACESSORIO codAcess,
	TB01010_NOME NomeAcess,
	TB02114_CODIGO Contrato,
	TB02114_NUMSERIE NumSerieMaq,
	TB02114_QTPROD qtde,
	TB02112_PAT,
	*
FROM TB02114
LEFT JOIN TB01010 ON TB01010_CODIGO = TB02114_ACESSORIO
LEFT JOIN TB02054 ON TB02054_NUMSERIE = TB02114_NUMSERIE
LEFT JOIN TB02112 ON TB02112_NUMSERIE = TB02114_NUMSERIE
	AND TB02112_CODIGO = TB02114_CODIGO
WHERE 
--TB02054_PAT = '030963' AND
--TB02114_CODIGO = '4264' AND 
TB02112_SITUACAO = 'A'