SELECT dbo.Par.Cod AS CodPar, dbo.WhereV2016.CodUserLogin , dbo.WhereV2016.WhereNumber
FROM dbo.Par CROSS JOIN WhereV2016
-- ---------------------------------------------------------------------------------------------------------
-- --------------------------------- PAR    PEL   DATA     --------------------------------------
Where ((Par.Cod IN (SELECT Cod FROM dbo.Par Where ParPelDataTyposCod = 0 ))
-- ------------------------------ CHECK ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataCheckTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataCheck
Where CodPelDataCheckTypos = ParPelDataCheckTyposCod
AND Epilogi = ParPelDataCheckEpilogi )
)))))
-- ------------------------------ CLIENT ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataClientTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataClient
Where CodPelDataClientTypos =ParPelDataClientTyposCod)
AND CodPEL = ParPelDataClientCod
)))))
-- ------------------------------ DD ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataDDTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataDD
Where CodPelDataDDTypos =ParPelDataDDTyposCod)
)))))
-- ------------------------------ EMail ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataEMailTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataEMail
Where CodPelDataEMAILTypos =ParPelDataEMAILTyposCod
))))))
-- ------------------------------ File ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataFileTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataFile
Where CodPelDataFileTypos =ParPelDataFileTyposCod
))))))
-- ------------------------------ HM ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataHmTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataHM
Where CodPelDataHMTypos =ParPelDataHMTyposCod
AND HM > ParPelDataHmMin AND HM < ParPelDataHmMax
))))))
-- ------------------------------ Monada ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataMonadaTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataMonada
Where CodPelDataMonadaTypos =ParPelDataMonadaTyposCod
AND Poso > ParPelDataMonadaMin AND Poso < ParPelDataMonadaMax
))))))
-- ------------------------------ Phone ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPhoneTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataPhone
Where CodPelDataPhoneTypos =ParPelDataPhoneTyposCod
))))))
-- ------------------------------ Photo ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPhotoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataPhoto
Where CodPelDataPhotoTypos =ParPelDataPhotoTyposCod
))))))
-- ------------------------------ Poso ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPosoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataPoso
Where CodPelDataPosoTypos =ParPelDataPosoTyposCod
AND Poso > ParPelDataPosoMin AND Poso < ParPelDataPosoMax
))))))
-- ------------------------------ Prom ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPromTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataProm
Where CodPelDataPromTypos =ParPelDataPromTyposCod)
AND CodPEL = ParPelDataPromCod
)))))
-- ------------------------------ Service ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataServiceTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataService
Where CodPelDataServiceTypos =ParPelDataServiceTyposCod)
AND CodPEL = ParPelDataServiceCod
)))))
-- ------------------------------ Text ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataTextTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataText
Where CodPelDataTextTypos =ParPelDataTextTyposCod
))))))
-- ------------------------------ WWW ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataWWWTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParPelData Where CodPelDataTypos = ParPelDataTyposCod
AND Cod IN (Select CodParPelData FROM ParPelDataWWW
Where CodPelDataWWWTypos =ParPelDataWWWTyposCod
)))))))

 

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

-- --------------------------------- PEL   DATA     --------------------------------------
AND ((Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataTyposCod = 0 ))
-- ------------------------------ CHECK ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataCheckTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataCheck
Where CodPelDataCheckTypos = PelDataCheckTyposCod
AND Epilogi = PelDataCheckEpilogi )
)))))
-- ------------------------------ CLIENT ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataClientTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataClient
Where CodPelDataClientTypos =PelDataClientTyposCod)
AND CodPEL = PelDataClientCod
)))))
-- ------------------------------ DD ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataDDTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataDD
Where CodPelDataDDTypos =PelDataDDTyposCod)
)))))
-- ------------------------------ EMail ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataEMailTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataEMail
Where CodPelDataEMAILTypos =PelDataEMAILTyposCod
))))))
-- ------------------------------ File ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataFileTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataFile
Where CodPelDataFileTypos =PelDataFileTyposCod
))))))
-- ------------------------------ HM ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataHmTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataHM
Where CodPelDataHMTypos =PelDataHMTyposCod
AND HM > PelDataHmMin AND HM < PelDataHmMax
))))))
-- ------------------------------ Monada ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataMonadaTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataMonada
Where CodPelDataMonadaTypos =PelDataMonadaTyposCod
AND Poso > PelDataMonadaMin AND Poso < PelDataMonadaMax
))))))
-- ------------------------------ Phone ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPhoneTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataPhone
Where CodPelDataPhoneTypos =PelDataPhoneTyposCod
))))))
-- ------------------------------ Photo ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPhotoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataPhoto
Where CodPelDataPhotoTypos =PelDataPhotoTyposCod
))))))
-- ------------------------------ Poso ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPosoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataPoso
Where CodPelDataPosoTypos =PelDataPosoTyposCod
AND Poso > PelDataPosoMin AND Poso < PelDataPosoMax
))))))
-- ------------------------------ Prom ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataPromTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataProm
Where CodPelDataPromTypos =PelDataPromTyposCod)
AND CodPEL = PelDataPromCod
)))))
-- ------------------------------ Service ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataServiceTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataService
Where CodPelDataServiceTypos =PelDataServiceTyposCod)
AND CodPEL = PelDataServiceCod
)))))
-- ------------------------------ Text ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataTextTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataText
Where CodPelDataTextTypos =PelDataTextTyposCod
))))))
-- ------------------------------ WWW ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where PelDataWWWTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.PelData Where CodPelDataTypos = PelDataTyposCod
AND Cod IN (Select CodPelData FROM PelDataWWW
Where CodPelDataWWWTypos =PelDataWWWTyposCod
))))))

)