SELECT dbo.Par.Cod AS CodPar, dbo.WhereV2016.CodUserLogin , dbo.WhereV2016.WhereNumber
FROM dbo.Par CROSS JOIN WhereV2016

-- -----------------------------------------------------------------------------------
-- --------------          PAR  IDOSPARTIDA   ------------------------------------
Where ((Par.Cod IN (SELECT Cod FROM dbo.Par Where ParIdosPartidaDataTyposCod = 0 ))
-- ------------------------------ CHECK ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataCheckTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataCheck
Where CodIdosPartidaDataCheckTypos = ParIdosPartidaDataCheckTyposCod
AND Epilogi = ParIdosPartidaDataCheckEpilogi )
)))))
-- ------------------------------ CLIENT ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataClientTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataClient
Where CodIdosPartidaDataClientTypos =ParIdosPartidaDataClientTyposCod)
AND CodPEL = ParIdosPartidaDataClientCod
)))))
-- ------------------------------ DD ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataDDTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataDD
Where CodIdosPartidaDataDDTypos =ParIdosPartidaDataDDTyposCod)
)))))
-- ------------------------------ EMail ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataEMailTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataEMail
Where CodIdosPartidaDataEMAILTypos =ParIdosPartidaDataEMAILTyposCod
))))))
-- ------------------------------ File ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataFileTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataFile
Where CodIdosPartidaDataFileTypos =ParIdosPartidaDataFileTyposCod
))))))
-- ------------------------------ HM ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataHmTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataHM
Where CodIdosPartidaDataHMTypos =ParIdosPartidaDataHMTyposCod
AND HM > ParIdosPartidaDataHmMin AND HM < ParIdosPartidaDataHmMax
))))))
-- ------------------------------ Monada ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataMonadaTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataMonada
Where CodIdosPartidaDataMonadaTypos =ParIdosPartidaDataMonadaTyposCod
AND Poso > ParIdosPartidaDataMonadaMin AND Poso < ParIdosPartidaDataMonadaMax
))))))
-- ------------------------------ Phone ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPhoneTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataPhone
Where CodIdosPartidaDataPhoneTypos =ParIdosPartidaDataPhoneTyposCod
))))))
-- ------------------------------ Photo ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPhotoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataPhoto
Where CodIdosPartidaDataPhotoTypos =ParIdosPartidaDataPhotoTyposCod
))))))
-- ------------------------------ Poso ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPosoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataPoso
Where CodIdosPartidaDataPosoTypos =ParIdosPartidaDataPosoTyposCod
AND Poso > ParIdosPartidaDataPosoMin AND Poso < ParIdosPartidaDataPosoMax
))))))
-- ------------------------------ Prom ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPromTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataProm
Where CodIdosPartidaDataPromTypos =ParIdosPartidaDataPromTyposCod)
AND CodPEL = ParIdosPartidaDataPromCod
)))))
-- ------------------------------ Service ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataServiceTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataService
Where CodIdosPartidaDataServiceTypos =ParIdosPartidaDataServiceTyposCod)
AND CodPEL = ParIdosPartidaDataServiceCod
)))))
-- ------------------------------ Text ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataTextTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataText
Where CodIdosPartidaDataTextTypos =ParIdosPartidaDataTextTyposCod
))))))
-- ------------------------------ WWW ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataWWWTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
Where Cod IN (Select CodParIdosPartida FROM ParIdosPartidaDataWWW
Where CodIdosPartidaDataWWWTypos =ParIdosPartidaDataWWWTyposCod
)))))))
-- --------------          IDOS     PARTIDA   ------------------------------------
AND ((Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataTyposCod = 0 ))
-- ------------------------------ CHECK ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataCheckTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataCheck
Where CodIdosPartidaDataCheckTypos = IdosPartidaDataCheckTyposCod
AND Epilogi = IdosPartidaDataCheckEpilogi )
)))))
-- ------------------------------ CLIENT ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataClientTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataClient
Where CodIdosPartidaDataClientTypos =IdosPartidaDataClientTyposCod)
AND CodPEL = IdosPartidaDataClientCod
)))))
-- ------------------------------ DD ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataDDTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataDD
Where CodIdosPartidaDataDDTypos =IdosPartidaDataDDTyposCod)
)))))
-- ------------------------------ EMail ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataEMailTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataEMail
Where CodIdosPartidaDataEMAILTypos =IdosPartidaDataEMAILTyposCod
))))))
-- ------------------------------ File ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataFileTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataFile
Where CodIdosPartidaDataFileTypos =IdosPartidaDataFileTyposCod
))))))
-- ------------------------------ HM ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataHmTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataHM
Where CodIdosPartidaDataHMTypos =IdosPartidaDataHMTyposCod
AND HM > IdosPartidaDataHmMin AND HM < IdosPartidaDataHmMax
))))))
-- ------------------------------ Monada ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataMonadaTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataMonada
Where CodIdosPartidaDataMonadaTypos =IdosPartidaDataMonadaTyposCod
AND Poso > IdosPartidaDataMonadaMin AND Poso < IdosPartidaDataMonadaMax
))))))
-- ------------------------------ Phone ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPhoneTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataPhone
Where CodIdosPartidaDataPhoneTypos =IdosPartidaDataPhoneTyposCod
))))))
-- ------------------------------ Photo ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPhotoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataPhoto
Where CodIdosPartidaDataPhotoTypos =IdosPartidaDataPhotoTyposCod
))))))
-- ------------------------------ Poso ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPosoTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataPoso
Where CodIdosPartidaDataPosoTypos =IdosPartidaDataPosoTyposCod
AND Poso > IdosPartidaDataPosoMin AND Poso < IdosPartidaDataPosoMax
))))))
-- ------------------------------ Prom ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataPromTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataProm
Where CodIdosPartidaDataPromTypos =IdosPartidaDataPromTyposCod)
AND CodPEL = IdosPartidaDataPromCod
)))))
-- ------------------------------ Service ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataServiceTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataService
Where CodIdosPartidaDataServiceTypos =IdosPartidaDataServiceTyposCod)
AND CodPEL = IdosPartidaDataServiceCod
)))))
-- ------------------------------ Text ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataTextTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataText
Where CodIdosPartidaDataTextTypos =IdosPartidaDataTextTyposCod
))))))
-- ------------------------------ WWW ------------------------
OR ( (Par.Cod IN (SELECT Cod FROM dbo.Par Where IdosPartidaDataWWWTyposCod = 0 )
OR (Par.Cod IN ( (SELECT Cod FROM dbo.ParIdosPartida
WHERE Cod IN (Select CodIdosPartida FROM IdosPartidaDataWWW
Where CodIdosPartidaDataWWWTypos =IdosPartidaDataWWWTyposCod
)))))))