
/*Skrypt wyswietla wszystkie wpisy w tabelach dotyczace firmy o wskazanym ID.
ID firmy, ktora chcemy wyswietlic nalezy wprowadzic w pierwszym SET (@firmToDelete)*/

DECLARE @firmToDelete uniqueidentifier,	
		@addressToDelete uniqueidentifier
SET @firmToDelete = ''
SET @addressToDelete = (SELECT addressID FROM [common].[address] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm')

SELECT * FROM firm.firm WHERE firmID = @firmToDelete
SELECT * FROM [common].[address] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1

SELECT * FROM [common].[relation] WHERE [remoteID] = @firmToDelete

SELECT * FROM [common].[history] WHERE ([parentRemoteSource] = 'firm' AND [parentRemoteID] = @firmToDelete) OR ([navigateRemoteSource] = 'firm' AND [navigateRemoteID] = @firmToDelete) OR ([remoteID] = @firmToDelete AND [remoteSource] = 'firm') --AND [status] > -1
SELECT * FROM [document].[invoice] WHERE [recipientID] = @firmToDelete OR [payerID] = @firmToDelete OR [issuerID] = @firmToDelete OR ([remoteSource] = 'firm' AND [remoteID] = @firmToDelete) --AND [status] > -1	
SELECT * FROM [document].[order] WHERE [firmID] = @firmToDelete OR [deliveryFirmID]	 = @firmToDelete
SELECT * FROM [log].[wall] WHERE ([remoteID] = @firmToDelete AND [remoteSource] = 'firm') OR ([parentRemoteSource] = 'firm' AND [parentRemoteID] = @firmToDelete)
SELECT * FROM [product].[product] WHERE [ownerFirmID] = @firmToDelete OR [dealerFirmID] = @firmToDelete --AND [status] > -1
SELECT * FROM [wms].[commision] WHERE [firmID] = @firmToDelete OR [addressID] = @addressToDelete	 --AND [status] > -1

SELECT * FROM [document].[Agreement] WHERE [firmID] = @firmToDelete --AND [status] > -1
SELECT * FROM [document].[document] WHERE [firmID] = @firmToDelete --AND [status] > -1
SELECT * FROM [document].[toolRegistry] WHERE [firmID] = @firmToDelete --AND [status] > -1
SELECT * FROM [firm].[contact] WHERE [firmID] = @firmToDelete --AND [status] > -1
SELECT * FROM [wms].[itemSupplier] WHERE [firmID] = @firmToDelete --AND [status] > -1

SELECT * FROM [common].[paymentSchedule] WHERE [payerID] = @firmToDelete OR ([remoteID] = @firmToDelete AND [remoteSource] = 'firm') --AND [status] > -1

SELECT * FROM [document].[offer] WHERE [firmID] = @firmToDelete OR ([remoteID] = @firmToDelete AND [remoteSource] = 'firm') --AND [status] > -1
SELECT * FROM [event].[opportunity] WHERE	[firmID] = @firmToDelete OR ([remoteID] = @firmToDelete AND [remoteSource] = 'firm') --AND [status] > -1
SELECT * FROM [firm].[campaignLine] WHERE	[firmID] = @firmToDelete OR ([remoteID] = @firmToDelete AND [remoteSource] = 'firm') --AND [status] > -1

SELECT * FROM [dbo].[synchronizationLog] WHERE [remoteID] = @firmToDelete

SELECT * FROM [accounting].[customeAccounting] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm'
SELECT * FROM [common].[clipboard] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm'
SELECT * FROM [common].[stats] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm'
SELECT * FROM [common].[tag] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm'
SELECT * FROM [product].[productRelation] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm'

SELECT * FROM [common].[Memo] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[bankAccount] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[attributeGroupComponentRelation] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[classification] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[comment] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[fileCad] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[fileRepository] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[teamcost] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [common].[timesheet] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [event].[iAttendee] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [event].[icalendar] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [event].[ievent] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [event].[task] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [mail].[mail] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [mail].[mailNotification] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [mail].[mailRelation] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [project].[project] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [user].[groupRelation] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [user].[userRelation] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [wms].[item] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [wms].[location] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [wms].[structure] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [wms].[technologyLine] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
SELECT * FROM [wms].[technologyMade] WHERE [remoteID] = @firmToDelete AND [remoteSource] = 'firm' --AND [status] > -1
