-- pokazanie czy wygenerowany do PIT-4R o konkretnym GUIDie ma przypisany US

SELECT 	   
			 US_GUID,p.rok, IFNULL(u.KOD_urzedu, "brak") AS KOD_urzedu, d.doc_id,  d.doc_type, d.doc_ver, d.doc_owner					  														
		FROM `pit_4r` p
		JOIN e_doc_def d ON p.e_Doc_Def_ID = d.owner_doc_Id
		LEFT JOIN `US` u ON u.GUID = p.US_GUID
		WHERE 
			p.GUID = '{80490F71-59F7-4C0F-9909-0619F3A11861}';

-- pokazanie czy wygenerowany do PIT-8AR o konkretnym GUIDie ma przypisany US
SELECT 	   
			 US_GUID,p.rok, IFNULL(u.KOD_urzedu, "brak") AS KOD_urzedu, d.doc_id,  d.doc_type, d.doc_ver, d.doc_owner					  														
		FROM `pit_8ar` p
		JOIN e_doc_def d ON p.e_Doc_Def_ID = d.owner_doc_Id
		LEFT JOIN `US` u ON u.GUID = p.US_GUID
		WHERE 
			p.GUID = 'XXXXXXXXX';
			
				
			
			
			
			
			SELECT * FROM US WHERE Kod_urzedu='1471';
			
			SELECT * FROM IReg WHERE IdKEy LIKE 'urz%pit%';
			
		
-- pokazanie PIT-4R o konkretnym GUID w kolumnie US_GUID		
					
			SELECT * FROM pit_4r WHERE GUID = '{80490F71-59F7-4C0F-9909-0619F3A11861}';
			
			
-- pokazanie PIT-8AR o konkretnym GUID	w kolumnie US_GUID		
			SELECT * FROM pit_8ar WHERE GUID = '{80490F71-59F7-4C0F-9909-0619F3A11861}';
			