我在查询构建器中构建的查询遇到麻烦。
我认为查询生成器是解决方案,因为我的搜索公式可以选择很多选项进行搜索。
我一直在寻找其他有类似问题的人,发现Access 2013在保留字方面更加敏感(因此,我遍历整个数据库并删除了可能有问题的所有字)和该查询builder应该能够处理255列数据-问题出现时,我的查询只有75列长。而且我需要查询至少有两列才能完成查询。
查询是一个append
查询,在将数据导出到excel之前将其收集在单个表中。
查询生成器的SQL很长,我认为它可能太复杂了
以下是查询构建器SQL视图中的代码:
INSERT INTO
tblResultsGeneral ( ReGRecordNumber, ReGUVNumber, ReGDate, RefNoInformer, ReGFullName, ReGOfficielObserver, ReGCountry, ReGProvince, ReGMuncipality, ReGNearestTown, ReGAreaName, ReGPathNumber, ReGSCALP, ReGValidateYes, ReGFieldTripYes, ReGScatYes, ReGPreyYes, ReGOtherDNAYes, ReGSightingYes, ReGTrackYes, ReGHowlYes, ReGUrinBloodYes, ReGCameraYes, ReGDenYes, ReGInsideWolfZone, ReGSampleType, ReGSampleEvidence, ReGDogPresent, ReGGELat, ReGGELong, ReGCoordinates, RefNoCoorSys, ReGUTMQuadrant, ReGUTMCoorX, ReGUTMCoorY, ReGPrecision, RefNoValidate, ReGSenckLabID, ReGSenckType_mtDNA, ReGSenckHaploType, ReGSenckInfo_mtDNA, ReGSenckType_NucleusDNA, ReGSenckInfo_NucleusDNA, ReGNumberOfAnimalsCam, ReGNumberOfAnimalsSight, ReGFullNameWriterCam, ReGFullNameWriterSight, ReGFullNameWriterHowl, ReGFullNameWriterOther, ReGFullNameWriterPrey, ReGFullNameWriterScat, ReGFullNameWriterTrack, ReGFullNameWriterUrinBlood, ReGFullNameWriterDen, RefNoValidateSpecies, ReGValidateGenus, ReGValidateSpecies, ReGValidateDanishName, ReGPackName, ReGIndividual, ReGIndiSex, ReGIndiBornYear, ReGIndiBornPlace, ReGIndiDead, ReGIndiDeadCause, ReGProbIndiGuess, ReGIndiAgeAtSampleTime, ReGTerritoryName, ReGMonitoringYear, ReGPhotoNotes, ReGPermissionToUsePhotoText, ReGPhotoFiles )
SELECT
tblRecord.RecRecordNumber,
tblUVNumber.UVNo,
tblRecord.RecDate,
tblRecord.RefNoInformer,
tblPersons.PerFullName,
tblPersons.PerOfficielObserver,
tblLocation.LocCountry,
tblLocation.LocProvince,
tblLocation.LocMuncipality,
tblLocation.LocNearestTown,
tblLocation.LocAreaName,
tblFieldTrip.FiTPathNumber,
tblValidate.ValSCALP,
tblRecord.RecValidateYes,
tblRecord.RecFieldTripYes,
tblRecord.RecScatYes,
tblRecord.RecPreyYes,
tblRecord.RecOtherDNAYes,
tblRecord.RecSightingYes,
tblRecord.RecTrackYes,
tblRecord.RecHowlYes,
tblRecord.RecUrinBloodYes,
tblRecord.RecCameraYes,
tblRecord.RecDenYes,
tblValidate.ValInsideWolfZone,
tblRecord.RecSampleType,
tblRecord.RecSampleEvidence,
tblRecord.RecDogPresent,
tblRecord.RecGELat,
tblRecord.RecGELong,
tblRecord.RecCoordinates,
tblRecord.RefNoCoorSys,
tblRecord.RecUTMQuadrant,
tblRecord.RecUTMCoorX,
tblRecord.RecUTMCoorY,
tblLocPrecision.LocationPrecision,
tblRecord.RefNoValidate,
tblValidate.ValSenckLabID,
tblValidate.ValSenckType_mtDNA,
tblValidate.ValSenckHaploType,
tblValidate.ValSenckInfo_mtDNA,
tblValidate.ValSenckType_KernDNA,
tblValidate.ValSenckInfo_KernDNA,
tblAnimal_1.AniNumberOfAnimals,
tblAnimal.AniNumberOfAnimals,
tblPersons_1.PerFullName,
tblPersons_2.PerFullName,
tblPersons_3.PerFullName,
tblPersons_4.PerFullName,
tblPersons_5.PerFullName,
tblPersons_6.PerFullName,
tblPersons_7.PerFullName,
tblPersons_8.PerFullName,
tblPersons_9.PerFullName,
tblValidate.RefNoValSpecies,
tblValidateSpecies.ValSpeGenus,
tblValidateSpecies.ValSpeSpecies,
tblValidateSpecies.ValSpeDanishName,
tblPack.PackName,
tblIndividual.Individual,
tblIndividual.IndiSex,
tblIndividual.IndiBornYear,
tblIndividual.IndiBornPlace,
tblIndividual.IndiDead,
tblIndividual.IndiDeadCause,
tblValidate.RefNoProbIndiGuess,
tblValidate.ValIndiAgeAtSampleTime,
tblTerritoryName.TerritoryName,
tblMonitoringYear.MonYear,
tblPhotoDoc.PhDPhotoNotes,
tblPhotoDoc.PhDPermissionToUsePhotoText,
tblPhotoDoc.PhDPhotoFiles
FROM
(
tblDen
INNER JOIN
(
tblIndividual
INNER JOIN
(
(tblValidateSpecies
INNER JOIN
(
tblPack
INNER JOIN
tblValidate
ON tblPack.KeyPack = tblValidate.RefNoPack
)
ON tblValidateSpecies.KeyValidateSpecies = tblValidate.RefNoValSpecies)
INNER JOIN
(
tblUVNumber
INNER JOIN
(
(tblPersons AS tblPersons_8
INNER JOIN
tblUrinBlood
ON tblPersons_8.KeyPersons = tblUrinBlood.RefNoWriterUrinBlood)
INNER JOIN
(
(tblPersons AS tblPersons_7
INNER JOIN
tblTrack
ON tblPersons_7.KeyPersons = tblTrack.RefNoWriterTrack)
INNER JOIN
(
tblTerritoryName
INNER JOIN
(
(tblAnimal
INNER JOIN
(
tblPersons AS tblPersons_2
INNER JOIN
tblSighting
ON tblPersons_2.KeyPersons = tblSighting.RefNoWriterSight
)
ON tblAnimal.KeyAnimal = tblSighting.RefNoAnimal)
INNER JOIN
(
(tblPersons AS tblPersons_6
INNER JOIN
tblScat
ON tblPersons_6.KeyPersons = tblScat.RefNoWriterScat)
INNER JOIN
(
(tblPersons AS tblPersons_5
INNER JOIN
tblPrey
ON tblPersons_5.KeyPersons = tblPrey.RefNoWriterPrey)
INNER JOIN
(
tblPhotoDoc
INNER JOIN
(
tblPersons
INNER JOIN
(
(tblPersons AS tblPersons_4
INNER JOIN
tblOtherDNA
ON tblPersons_4.KeyPersons = tblOtherDNA.RefNoWriterOther)
INNER JOIN
(
tblMonitoringYear
INNER JOIN
(
tblLocPrecision
INNER JOIN
(
tblLocation
INNER JOIN
(
(tblPersons AS tblPersons_3
INNER JOIN
tblHowl
ON tblPersons_3.KeyPersons = tblHowl.RefNoWriterHowl)
INNER JOIN
(
tblFieldTrip
INNER JOIN
(
(tblAnimal AS tblAnimal_1
INNER JOIN
(
tblPersons AS tblPersons_1
INNER JOIN
tblCamera
ON tblPersons_1.KeyPersons = tblCamera.RefNoWriterCam
)
ON tblAnimal_1.KeyAnimal = tblCamera.RefNoAnimal)
INNER JOIN
tblRecord
ON tblCamera.KeyCamera = tblRecord.RefNoCamera
)
ON tblFieldTrip.KeyFieldTrip = tblRecord.RefNoFieldTrip
)
ON tblHowl.KeyHowl = tblRecord.RefNoHowl
)
ON tblLocation.KeyLocation = tblRecord.RefNoLocation
)
ON tblLocPrecision.KeyLocPrecision = tblRecord.RefNoPrecision
)
ON tblMonitoringYear.KeyMonYear = tblRecord.RefNoMonYear
)
ON tblOtherDNA.KeyOtherDNA = tblRecord.RefNoOtherDNA
)
ON tblPersons.KeyPersons = tblRecord.RefNoInformer
)
ON tblPhotoDoc.KeyPhoto = tblRecord.RefNoPhotoDoc
)
ON tblPrey.KeyPrey = tblRecord.RefNoPrey
)
ON tblScat.KeyScat = tblRecord.RefNoScat
)
ON tblSighting.KeySigthing = tblRecord.RefNoSighting
)
ON tblTerritoryName.KeyTerritoryName = tblRecord.RefNoTerritoryName
)
ON tblTrack.KeyTrack = tblRecord.RefNoTrack
)
ON tblUrinBlood.KeyUrinBlood = tblRecord.RefNoUrinBlood
)
ON tblUVNumber.KeyUVNo = tblRecord.RefNoUVNo
)
ON tblValidate.KeyValidate = tblRecord.RefNoValidate
)
ON tblIndividual.KeyIndividual = tblValidate.RefNoIndi
)
ON tblDen.KeyDen = tblRecord.RefNoDen
)
INNER JOIN
tblPersons AS tblPersons_9
ON tblDen.RefNoWriterDen = tblPersons_9.KeyPersons
WHERE
(
((tblRecord.RecRecordNumber) Like [Formularer] ! [frmSearchGeneral].[FindRecord] & "*")
AND
(
(tblUVNumber.UVNo) Like [Formularer] ! [frmSearchGeneral].[FindUV] & "*"
)
AND
(
(tblRecord.RecDate) Between IIf([Forms] ! [frmSearchGeneral].[FindDateStart] Is Null, # 1 / 1 / 1000 # , [Forms] ! [frmSearchGeneral].[FindDateStart]) And IIf([Forms] ! [frmSearchGeneral].[FindDateEnd] Is Null, # 12 / 31 / 9999 # , [Forms] ! [frmSearchGeneral].[FindDateEnd])
)
AND
(
(tblPersons.PerFullName) Like [Formularer] ! [frmSearchGeneral].[FindPerson] & "*"
)
AND
(
(tblPersons.PerOfficielObserver) Like [Formularer] ! [frmSearchGeneral].[FindOfficial] & "*"
)
AND
(
(tblLocation.LocCountry) Like [Formularer] ! [frmSearchGeneral].[FindCountry] & "*"
)
AND
(
(tblLocation.LocProvince) Like [Formularer] ! [frmSearchGeneral].[FindProvince] & "*"
)
AND
(
(tblLocation.LocMuncipality) Like [Formularer] ! [frmSearchGeneral].[FindMuncipality] & "*"
)
AND
(
(tblLocation.LocNearestTown) Like [Formularer] ! [frmSearchGeneral].[FindNearestTown] & "*"
)
AND
(
(tblLocation.LocAreaName) Like [Formularer] ! [frmSearchGeneral].[FindAreaName] & "*"
)
AND
(
(tblFieldTrip.FiTPathNumber) Like [Formularer] ! [frmSearchGeneral].[FindTrackNo] & "*"
)
AND
(
(tblValidate.ValSCALP) Like [Formularer] ! [frmSearchGeneral].[FindSCALP] & "*"
)
AND
(
(tblRecord.RecValidateYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindValidate] = Yes, [Formularer] ! [frmSearchGeneral].[FindValidate], "*")
)
AND
(
(tblRecord.RecScatYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindScat] = Yes, [Formularer] ! [frmSearchGeneral].[FindScat], "*")
)
AND
(
(tblRecord.RecPreyYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindPrey] = Yes, [Formularer] ! [frmSearchGeneral].[FindPrey], "*")
)
AND
(
(tblRecord.RecOtherDNAYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindOtherDNA] = Yes, [Formularer] ! [frmSearchGeneral].[FindOtherDNA], "*")
)
AND
(
(tblRecord.RecSightingYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindSighting] = Yes, [Formularer] ! [frmSearchGeneral].[FindSighting], "*")
)
AND
(
(tblRecord.RecTrackYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindTrack] = Yes, [Formularer] ! [frmSearchGeneral].[FindTrack], "*")
)
AND
(
(tblRecord.RecHowlYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindHowl] = Yes, [Formularer] ! [frmSearchGeneral].[FindHowl], "*")
)
AND
(
(tblRecord.RecUrinBloodYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindUrinBlood] = Yes, [Formularer] ! [frmSearchGeneral].[FindUrinBlood], "*")
)
AND
(
(tblRecord.RecCameraYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindCamera] = Yes, [Formularer] ! [frmSearchGeneral].[FindCamera], "*")
)
AND
(
(tblValidate.ValInsideWolfZone) Like IIf([Formularer] ! [frmSearchGeneral].[FindWolfZone] = Yes, [formularer] ! [frmSearchGeneral].[FindWolfZone], "*")
)
AND
(
(tblValidate.RefNoValSpecies) Like [Formularer] ! [frmSearchGeneral].[FindValidateSpecies] & "*"
)
AND
(
(tblPack.PackName) Like [Formularer] ! [frmSearchGeneral].[FindPack] & "*"
)
AND
(
(tblIndividual.Individual) Like [Formularer] ! [frmSearchGeneral].[FindIndividual] & "*"
)
AND
(
(tblTerritoryName.TerritoryName) Like [formularer] ! [frmSearchGeneral].[FindTerritory] & "*"
)
AND
(
(tblRecord.Deactivated) = False
)
AND
(
(Year([RecDate])) = [Forms] ! [frmSearchGeneral].[FindYearSpecific]
)
)
OR
(
((tblRecord.RecRecordNumber) Like [Formularer] ! [frmSearchGeneral].[FindRecord] & "*")
AND
(
(tblUVNumber.UVNo) Like [Formularer] ! [frmSearchGeneral].[FindUV] & "*"
)
AND
(
(tblRecord.RecDate) Between IIf([Forms] ! [frmSearchGeneral].[FindDateStart] Is Null, # 1 / 1 / 1000 # , [Forms] ! [frmSearchGeneral].[FindDateStart]) And IIf([Forms] ! [frmSearchGeneral].[FindDateEnd] Is Null, # 12 / 31 / 9999 # , [Forms] ! [frmSearchGeneral].[FindDateEnd])
)
AND
(
(tblPersons.PerFullName) Like [Formularer] ! [frmSearchGeneral].[FindPerson] & "*"
)
AND
(
(tblPersons.PerOfficielObserver) Like [Formularer] ! [frmSearchGeneral].[FindOfficial] & "*"
)
AND
(
(tblLocation.LocCountry) Like [Formularer] ! [frmSearchGeneral].[FindCountry] & "*"
)
AND
(
(tblLocation.LocProvince) Like [Formularer] ! [frmSearchGeneral].[FindProvince] & "*"
)
AND
(
(tblLocation.LocMuncipality) Like [Formularer] ! [frmSearchGeneral].[FindMuncipality] & "*"
)
AND
(
(tblLocation.LocNearestTown) Like [Formularer] ! [frmSearchGeneral].[FindNearestTown] & "*"
)
AND
(
(tblLocation.LocAreaName) Like [Formularer] ! [frmSearchGeneral].[FindAreaName] & "*"
)
AND
(
(tblFieldTrip.FiTPathNumber) Like [Formularer] ! [frmSearchGeneral].[FindTrackNo] & "*"
)
AND
(
(tblValidate.ValSCALP) Like [Formularer] ! [frmSearchGeneral].[FindSCALP] & "*"
)
AND
(
(tblRecord.RecValidateYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindValidate] = Yes, [Formularer] ! [frmSearchGeneral].[FindValidate], "*")
)
AND
(
(tblRecord.RecScatYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindScat] = Yes, [Formularer] ! [frmSearchGeneral].[FindScat], "*")
)
AND
(
(tblRecord.RecPreyYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindPrey] = Yes, [Formularer] ! [frmSearchGeneral].[FindPrey], "*")
)
AND
(
(tblRecord.RecOtherDNAYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindOtherDNA] = Yes, [Formularer] ! [frmSearchGeneral].[FindOtherDNA], "*")
)
AND
(
(tblRecord.RecSightingYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindSighting] = Yes, [Formularer] ! [frmSearchGeneral].[FindSighting], "*")
)
AND
(
(tblRecord.RecTrackYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindTrack] = Yes, [Formularer] ! [frmSearchGeneral].[FindTrack], "*")
)
AND
(
(tblRecord.RecHowlYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindHowl] = Yes, [Formularer] ! [frmSearchGeneral].[FindHowl], "*")
)
AND
(
(tblRecord.RecUrinBloodYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindUrinBlood] = Yes, [Formularer] ! [frmSearchGeneral].[FindUrinBlood], "*")
)
AND
(
(tblRecord.RecCameraYes) Like IIf([Formularer] ! [frmSearchGeneral].[FindCamera] = Yes, [Formularer] ! [frmSearchGeneral].[FindCamera], "*")
)
AND
(
(tblValidate.ValInsideWolfZone) Like IIf([Formularer] ! [frmSearchGeneral].[FindWolfZone] = Yes, [formularer] ! [frmSearchGeneral].[FindWolfZone], "*")
)
AND
(
(tblValidate.RefNoValSpecies) Like [Formularer] ! [frmSearchGeneral].[FindValidateSpecies] & "*"
)
AND
(
(tblPack.PackName) Like [Formularer] ! [frmSearchGeneral].[FindPack] & "*"
)
AND
(
(tblIndividual.Individual) Like [Formularer] ! [frmSearchGeneral].[FindIndividual] & "*"
)
AND
(
(tblTerritoryName.TerritoryName) Like [formularer] ! [frmSearchGeneral].[FindTerritory] & "*"
)
AND
(
(tblRecord.Deactivated) = False
)
AND
(
(Year([RecDate])) Between IIf([Forms] ! [frmSearchGeneral].[FindYearStart] Is Null, # 1 / 1 / 1000 # , [Forms] ! [frmSearchGeneral].[FindYearStart]) And IIf([Forms] ! [frmSearchGeneral].[FindYearEnd] Is Null, # 12 / 31 / 9999 # , [Forms] ! [frmSearchGeneral].[FindYearEnd])
)
AND
(
([Forms] ! [frmSearchGeneral].[FindYearSpecific]) Is Null
)
)
;
这是Access从2分钟的搜索开始,然后将结果传递给我的地方:
“查询过于复杂”
我唯一要做的就是添加两个表(tblDen
和tblPersons_9
)和另外两列RecDenYes
(来自tblRecords
)和PerFullName
(来自tblPersons_9
)
要使查询完成,我需要添加另外两个表(tblAnimal_2
和tblAnimal_3
),以便能够添加这两列(AniNumberOfAnimals
和AniNumberOfAnimals
)会给我从tblHowl
和tblTrack
开始的动物数量。
答案 0 :(得分:-1)
这不是一个答案,而是更多的第一步。我会选择这个怪物,并使用sql formatter / pretty打印机对其进行解析以使其可读。我在这里使用的SQLInForm
记事本++插件:
SELECT
tblRecord.RecRecordNumber
, tblUVNumber.UVNo
, tblRecord.RecDate
, tblRecord.RefNoInformer
, tblPersons.PerFullName
, tblPersons.PerOfficielObserver
, tblLocation.LocCountry
, tblLocation.LocProvince
, tblLocation.LocMuncipality
, tblLocation.LocNearestTown
, tblLocation.LocAreaName
, tblFieldTrip.FiTPathNumber
, tblValidate.ValSCALP
, tblRecord.RecValidateYes
, tblRecord.RecFieldTripYes
, tblRecord.RecScatYes
, tblRecord.RecPreyYes
, tblRecord.RecOtherDNAYes
, tblRecord.RecSightingYes
, tblRecord.RecTrackYes
, tblRecord.RecHowlYes
, tblRecord.RecUrinBloodYes
, tblRecord.RecCameraYes
, tblRecord.RecDenYes
, tblValidate.ValInsideWolfZone
, tblRecord.RecSampleType
, tblRecord.RecSampleEvidence
, tblRecord.RecDogPresent
, tblRecord.RecGELat
, tblRecord.RecGELong
, tblRecord.RecCoordinates
, tblRecord.RefNoCoorSys
, tblRecord.RecUTMQuadrant
, tblRecord.RecUTMCoorX
, tblRecord.RecUTMCoorY
, tblLocPrecision.LocationPrecision
, tblRecord.RefNoValidate
, tblValidate.ValSenckLabID
, tblValidate.ValSenckType_mtDNA
, tblValidate.ValSenckHaploType
, tblValidate.ValSenckInfo_mtDNA
, tblValidate.ValSenckType_KernDNA
, tblValidate.ValSenckInfo_KernDNA
, tblAnimal_1.AniNumberOfAnimals
, tblAnimal.AniNumberOfAnimals
, tblPersons_1.PerFullName
, tblPersons_2.PerFullName
, tblPersons_3.PerFullName
, tblPersons_4.PerFullName
, tblPersons_5.PerFullName
, tblPersons_6.PerFullName
, tblPersons_7.PerFullName
, tblPersons_8.PerFullName
, tblPersons_9.PerFullName
, tblValidate.RefNoValSpecies
, tblValidateSpecies.ValSpeGenus
, tblValidateSpecies.ValSpeSpecies
, tblValidateSpecies.ValSpeDanishName
, tblPack.PackName
, tblIndividual.Individual
, tblIndividual.IndiSex
, tblIndividual.IndiBornYear
, tblIndividual.IndiBornPlace
, tblIndividual.IndiDead
, tblIndividual.IndiDeadCause
, tblValidate.RefNoProbIndiGuess
, tblValidate.ValIndiAgeAtSampleTime
, tblTerritoryName.TerritoryName
, tblMonitoringYear.MonYear
, tblPhotoDoc.PhDPhotoNotes
, tblPhotoDoc.PhDPermissionToUsePhotoText
, tblPhotoDoc.PhDPhotoFiles
FROM
(tblDen
INNER JOIN
(tblIndividual
INNER JOIN
((tblValidateSpecies
INNER JOIN
(tblPack
INNER JOIN
tblValidate
ON
tblPack.KeyPack = tblValidate.RefNoPack)
ON
tblValidateSpecies.KeyValidateSpecies = tblValidate.RefNoValSpecies)
INNER JOIN
(tblUVNumber
INNER JOIN
((tblPersons AS tblPersons_8
INNER JOIN
tblUrinBlood
ON
tblPersons_8.KeyPersons = tblUrinBlood.RefNoWriterUrinBlood)
INNER JOIN
((tblPersons AS tblPersons_7
INNER JOIN
tblTrack
ON
tblPersons_7.KeyPersons = tblTrack.RefNoWriterTrack)
INNER JOIN
(tblTerritoryName
INNER JOIN
((tblAnimal
INNER JOIN
(tblPersons AS tblPersons_2
INNER JOIN
tblSighting
ON
tblPersons_2.KeyPersons = tblSighting.RefNoWriterSight)
ON
tblAnimal.KeyAnimal = tblSighting.RefNoAnimal)
INNER JOIN
((tblPersons AS tblPersons_6
INNER JOIN
tblScat
ON
tblPersons_6.KeyPersons = tblScat.RefNoWriterScat)
INNER JOIN
((tblPersons AS tblPersons_5
INNER JOIN
tblPrey
ON
tblPersons_5.KeyPersons = tblPrey.RefNoWriterPrey)
INNER JOIN
(tblPhotoDoc
INNER JOIN
(tblPersons
INNER JOIN
((tblPersons AS tblPersons_4
INNER JOIN
tblOtherDNA
ON
tblPersons_4.KeyPersons = tblOtherDNA.RefNoWriterOther)
INNER JOIN
(tblMonitoringYear
INNER JOIN
(tblLocPrecision
INNER JOIN
(tblLocation
INNER JOIN
((tblPersons AS tblPersons_3
INNER JOIN
tblHowl
ON
tblPersons_3.KeyPersons = tblHowl.RefNoWriterHowl)
INNER JOIN
(tblFieldTrip
INNER JOIN
((tblAnimal AS tblAnimal_1
INNER JOIN
(tblPersons AS tblPersons_1
INNER JOIN
tblCamera
ON
tblPersons_1.KeyPersons = tblCamera.RefNoWriterCam)
ON
tblAnimal_1.KeyAnimal = tblCamera.RefNoAnimal)
INNER JOIN
tblRecord
ON
tblCamera.KeyCamera = tblRecord.RefNoCamera)
ON
tblFieldTrip.KeyFieldTrip = tblRecord.RefNoFieldTrip)
ON
tblHowl.KeyHowl = tblRecord.RefNoHowl)
ON
tblLocation.KeyLocation = tblRecord.RefNoLocation)
ON
tblLocPrecision.KeyLocPrecision = tblRecord.RefNoPrecision)
ON
tblMonitoringYear.KeyMonYear = tblRecord.RefNoMonYear)
ON
tblOtherDNA.KeyOtherDNA = tblRecord.RefNoOtherDNA)
ON
tblPersons.KeyPersons = tblRecord.RefNoInformer)
ON
tblPhotoDoc.KeyPhoto = tblRecord.RefNoPhotoDoc)
ON
tblPrey.KeyPrey = tblRecord.RefNoPrey)
ON
tblScat.KeyScat = tblRecord.RefNoScat)
ON
tblSighting.KeySigthing = tblRecord.RefNoSighting)
ON
tblTerritoryName.KeyTerritoryName = tblRecord.RefNoTerritoryName)
ON
tblTrack.KeyTrack = tblRecord.RefNoTrack)
ON
tblUrinBlood.KeyUrinBlood = tblRecord.RefNoUrinBlood)
ON
tblUVNumber.KeyUVNo = tblRecord.RefNoUVNo)
ON
tblValidate.KeyValidate = tblRecord.RefNoValidate)
ON
tblIndividual.KeyIndividual = tblValidate.RefNoIndi)
ON
tblDen.KeyDen = tblRecord.RefNoDen)
INNER JOIN
tblPersons AS tblPersons_9
ON
tblDen.RefNoWriterDen = tblPersons_9.KeyPersons
WHERE
(
(
(
tblRecord.RecRecordNumber
)
Like [Formularer]![frmSearchGeneral].[FindRecord] & "*"
)
AND
(
(
tblUVNumber.UVNo
)
Like [Formularer]![frmSearchGeneral].[FindUV] & "*"
)
AND
(
(
tblRecord.RecDate
)
Between IIf([Forms]![frmSearchGeneral].[FindDateStart] Is Null,#1/1/1000#,[Forms]![frmSearchGeneral].[FindDateStart]) And IIf([Forms]![frmSearchGeneral].[FindDateEnd] Is Null,#12/31/9999#,[Forms]![frmSearchGeneral].[FindDateEnd])
)
AND
(
(
tblPersons.PerFullName
)
Like [Formularer]![frmSearchGeneral].[FindPerson] & "*"
)
AND
(
(
tblPersons.PerOfficielObserver
)
Like [Formularer]![frmSearchGeneral].[FindOfficial] & "*"
)
AND
(
(
tblLocation.LocCountry
)
Like [Formularer]![frmSearchGeneral].[FindCountry] & "*"
)
AND
(
(
tblLocation.LocProvince
)
Like [Formularer]![frmSearchGeneral].[FindProvince] & "*"
)
AND
(
(
tblLocation.LocMuncipality
)
Like [Formularer]![frmSearchGeneral].[FindMuncipality] & "*"
)
AND
(
(
tblLocation.LocNearestTown
)
Like [Formularer]![frmSearchGeneral].[FindNearestTown] & "*"
)
AND
(
(
tblLocation.LocAreaName
)
Like [Formularer]![frmSearchGeneral].[FindAreaName] & "*"
)
AND
(
(
tblFieldTrip.FiTPathNumber
)
Like [Formularer]![frmSearchGeneral].[FindTrackNo] & "*"
)
AND
(
(
tblValidate.ValSCALP
)
Like [Formularer]![frmSearchGeneral].[FindSCALP] & "*"
)
AND
(
(
tblRecord.RecValidateYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindValidate]=Yes,[Formularer]![frmSearchGeneral].[FindValidate],"*")
)
AND
(
(
tblRecord.RecScatYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindScat]=Yes,[Formularer]![frmSearchGeneral].[FindScat],"*")
)
AND
(
(
tblRecord.RecPreyYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindPrey]=Yes,[Formularer]![frmSearchGeneral].[FindPrey],"*")
)
AND
(
(
tblRecord.RecOtherDNAYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindOtherDNA]=Yes,[Formularer]![frmSearchGeneral].[FindOtherDNA],"*")
)
AND
(
(
tblRecord.RecSightingYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindSighting]=Yes,[Formularer]![frmSearchGeneral].[FindSighting],"*")
)
AND
(
(
tblRecord.RecTrackYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindTrack]=Yes,[Formularer]![frmSearchGeneral].[FindTrack],"*")
)
AND
(
(
tblRecord.RecHowlYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindHowl]=Yes,[Formularer]![frmSearchGeneral].[FindHowl],"*")
)
AND
(
(
tblRecord.RecUrinBloodYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindUrinBlood]=Yes,[Formularer]![frmSearchGeneral].[FindUrinBlood],"*")
)
AND
(
(
tblRecord.RecCameraYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindCamera]=Yes,[Formularer]![frmSearchGeneral].[FindCamera],"*")
)
AND
(
(
tblValidate.ValInsideWolfZone
)
Like IIf([Formularer]![frmSearchGeneral].[FindWolfZone]=Yes,[formularer]![frmSearchGeneral].[FindWolfZone],"*")
)
AND
(
(
tblValidate.RefNoValSpecies
)
Like [Formularer]![frmSearchGeneral].[FindValidateSpecies] & "*"
)
AND
(
(
tblPack.PackName
)
Like [Formularer]![frmSearchGeneral].[FindPack] & "*"
)
AND
(
(
tblIndividual.Individual
)
Like [Formularer]![frmSearchGeneral].[FindIndividual] & "*"
)
AND
(
(
tblTerritoryName.TerritoryName
)
Like [formularer]![frmSearchGeneral].[FindTerritory] & "*"
)
AND
(
(
tblRecord.Deactivated
)
=False
)
AND
(
(
Year([RecDate])
)
=[Forms]![frmSearchGeneral].[FindYearSpecific]
)
)
OR
(
(
(
tblRecord.RecRecordNumber
)
Like [Formularer]![frmSearchGeneral].[FindRecord] & "*"
)
AND
(
(
tblUVNumber.UVNo
)
Like [Formularer]![frmSearchGeneral].[FindUV] & "*"
)
AND
(
(
tblRecord.RecDate
)
Between IIf([Forms]![frmSearchGeneral].[FindDateStart] Is Null,#1/1/1000#,[Forms]![frmSearchGeneral].[FindDateStart]) And IIf([Forms]![frmSearchGeneral].[FindDateEnd] Is Null,#12/31/9999#,[Forms]![frmSearchGeneral].[FindDateEnd])
)
AND
(
(
tblPersons.PerFullName
)
Like [Formularer]![frmSearchGeneral].[FindPerson] & "*"
)
AND
(
(
tblPersons.PerOfficielObserver
)
Like [Formularer]![frmSearchGeneral].[FindOfficial] & "*"
)
AND
(
(
tblLocation.LocCountry
)
Like [Formularer]![frmSearchGeneral].[FindCountry] & "*"
)
AND
(
(
tblLocation.LocProvince
)
Like [Formularer]![frmSearchGeneral].[FindProvince] & "*"
)
AND
(
(
tblLocation.LocMuncipality
)
Like [Formularer]![frmSearchGeneral].[FindMuncipality] & "*"
)
AND
(
(
tblLocation.LocNearestTown
)
Like [Formularer]![frmSearchGeneral].[FindNearestTown] & "*"
)
AND
(
(
tblLocation.LocAreaName
)
Like [Formularer]![frmSearchGeneral].[FindAreaName] & "*"
)
AND
(
(
tblFieldTrip.FiTPathNumber
)
Like [Formularer]![frmSearchGeneral].[FindTrackNo] & "*"
)
AND
(
(
tblValidate.ValSCALP
)
Like [Formularer]![frmSearchGeneral].[FindSCALP] & "*"
)
AND
(
(
tblRecord.RecValidateYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindValidate]=Yes,[Formularer]![frmSearchGeneral].[FindValidate],"*")
)
AND
(
(
tblRecord.RecScatYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindScat]=Yes,[Formularer]![frmSearchGeneral].[FindScat],"*")
)
AND
(
(
tblRecord.RecPreyYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindPrey]=Yes,[Formularer]![frmSearchGeneral].[FindPrey],"*")
)
AND
(
(
tblRecord.RecOtherDNAYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindOtherDNA]=Yes,[Formularer]![frmSearchGeneral].[FindOtherDNA],"*")
)
AND
(
(
tblRecord.RecSightingYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindSighting]=Yes,[Formularer]![frmSearchGeneral].[FindSighting],"*")
)
AND
(
(
tblRecord.RecTrackYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindTrack]=Yes,[Formularer]![frmSearchGeneral].[FindTrack],"*")
)
AND
(
(
tblRecord.RecHowlYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindHowl]=Yes,[Formularer]![frmSearchGeneral].[FindHowl],"*")
)
AND
(
(
tblRecord.RecUrinBloodYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindUrinBlood]=Yes,[Formularer]![frmSearchGeneral].[FindUrinBlood],"*")
)
AND
(
(
tblRecord.RecCameraYes
)
Like IIf([Formularer]![frmSearchGeneral].[FindCamera]=Yes,[Formularer]![frmSearchGeneral].[FindCamera],"*")
)
AND
(
(
tblValidate.ValInsideWolfZone
)
Like IIf([Formularer]![frmSearchGeneral].[FindWolfZone]=Yes,[formularer]![frmSearchGeneral].[FindWolfZone],"*")
)
AND
(
(
tblValidate.RefNoValSpecies
)
Like [Formularer]![frmSearchGeneral].[FindValidateSpecies] & "*"
)
AND
(
(
tblPack.PackName
)
Like [Formularer]![frmSearchGeneral].[FindPack] & "*"
)
AND
(
(
tblIndividual.Individual
)
Like [Formularer]![frmSearchGeneral].[FindIndividual] & "*"
)
AND
(
(
tblTerritoryName.TerritoryName
)
Like [formularer]![frmSearchGeneral].[FindTerritory] & "*"
)
AND
(
(
tblRecord.Deactivated
)
=False
)
AND
(
(
Year([RecDate])
)
Between IIf([Forms]![frmSearchGeneral].[FindYearStart] Is Null,#1/1/1000#,[Forms]![frmSearchGeneral].[FindYearStart]) And IIf([Forms]![frmSearchGeneral].[FindYearEnd] Is Null,#12/31/9999#,[Forms]![frmSearchGeneral].[FindYearEnd])
)
AND
(
(
[Forms]![frmSearchGeneral].[FindYearSpecific]
)
Is Null
)
)
;
现在是606行弥天大谎。
Access喜欢它一些括号,在大多数情况下,它们是100%不需要的。实际上,除了WHERE子句中的单个OR
条件外,其余的括号都是多余的。当将这些嵌套的INNER JOIN像这样粘贴在一起时,Access也就是A级哑巴。根本不需要它们,并且ON子句只是随意散布。从技术上讲这是正确的,但是调试起来很麻烦。
重写:
SELECT
tblRecord.RecRecordNumber
, tblUVNumber.UVNo
, tblRecord.RecDate
, tblRecord.RefNoInformer
, tblPersons.PerFullName
, tblPersons.PerOfficielObserver
, tblLocation.LocCountry
, tblLocation.LocProvince
, tblLocation.LocMuncipality
, tblLocation.LocNearestTown
, tblLocation.LocAreaName
, tblFieldTrip.FiTPathNumber
, tblValidate.ValSCALP
, tblRecord.RecValidateYes
, tblRecord.RecFieldTripYes
, tblRecord.RecScatYes
, tblRecord.RecPreyYes
, tblRecord.RecOtherDNAYes
, tblRecord.RecSightingYes
, tblRecord.RecTrackYes
, tblRecord.RecHowlYes
, tblRecord.RecUrinBloodYes
, tblRecord.RecCameraYes
, tblRecord.RecDenYes
, tblValidate.ValInsideWolfZone
, tblRecord.RecSampleType
, tblRecord.RecSampleEvidence
, tblRecord.RecDogPresent
, tblRecord.RecGELat
, tblRecord.RecGELong
, tblRecord.RecCoordinates
, tblRecord.RefNoCoorSys
, tblRecord.RecUTMQuadrant
, tblRecord.RecUTMCoorX
, tblRecord.RecUTMCoorY
, tblLocPrecision.LocationPrecision
, tblRecord.RefNoValidate
, tblValidate.ValSenckLabID
, tblValidate.ValSenckType_mtDNA
, tblValidate.ValSenckHaploType
, tblValidate.ValSenckInfo_mtDNA
, tblValidate.ValSenckType_KernDNA
, tblValidate.ValSenckInfo_KernDNA
, tblAnimal_1.AniNumberOfAnimals
, tblAnimal.AniNumberOfAnimals
, tblPersons_1.PerFullName
, tblPersons_2.PerFullName
, tblPersons_3.PerFullName
, tblPersons_4.PerFullName
, tblPersons_5.PerFullName
, tblPersons_6.PerFullName
, tblPersons_7.PerFullName
, tblPersons_8.PerFullName
, tblPersons_9.PerFullName
, tblValidate.RefNoValSpecies
, tblValidateSpecies.ValSpeGenus
, tblValidateSpecies.ValSpeSpecies
, tblValidateSpecies.ValSpeDanishName
, tblPack.PackName
, tblIndividual.Individual
, tblIndividual.IndiSex
, tblIndividual.IndiBornYear
, tblIndividual.IndiBornPlace
, tblIndividual.IndiDead
, tblIndividual.IndiDeadCause
, tblValidate.RefNoProbIndiGuess
, tblValidate.ValIndiAgeAtSampleTime
, tblTerritoryName.TerritoryName
, tblMonitoringYear.MonYear
, tblPhotoDoc.PhDPhotoNotes
, tblPhotoDoc.PhDPermissionToUsePhotoText
, tblPhotoDoc.PhDPhotoFiles
FROM
/*TblRecord is the driver here. Everything else joins to it snowflake style*/
tblRecord
/*bring in camera data*/
INNER JOIN
tblCamera
ON
tblCamera.KeyCamera = tblRecord.RefNoCamera
INNER JOIN
tblAnimal AS tblAnimal_1
ON
tblAnimal_1.KeyAnimal = tblCamera.RefNoAnimal
INNER JOIN
tblPersons AS tblPersons_1
ON
tblPersons_1.KeyPersons = tblCamera.RefNoWriterCam
/*Howl Data*/
INNER JOIN
tblHowl
ON
tblHowl.KeyHowl = tblRecord.RefNoHowl
INNER JOIN
tblPersons AS tblPersons_3
ON
tblPersons_3.KeyPersons = tblHowl.RefNoWriterHowl
/*Field Trip Data*/
INNER JOIN
tblFieldTrip
ON
tblFieldTrip.KeyFieldTrip = tblRecord.RefNoFieldTrip
/*Location Data*/
INNER JOIN
tblLocation
ON
tblLocation.KeyLocation = tblRecord.RefNoLocation
/*Precision Data*/
INNER JOIN
tblLocPrecision
ON
tblLocPrecision.KeyLocPrecision = tblRecord.RefNoPrecision
/*Monitoring Year Data*/
INNER JOIN
tblMonitoringYear
ON
tblMonitoringYear.KeyMonYear = tblRecord.RefNoMonYear
/*Other DNA data*/
INNER JOIN
tblOtherDNA
ON
tblOtherDNA.KeyOtherDNA = tblRecord.RefNoOtherDNA
INNER JOIN
tblPersons AS tblPersons_4
ON
tblPersons_4.KeyPersons = tblOtherDNA.RefNoWriterOther
/*Primary Persons data for the record*/
INNER JOIN
tblPersons
ON
tblPersons.KeyPersons = tblRecord.RefNoInformer
/*Photo Doc Data*/
INNER JOIN
tblPhotoDoc
ON
tblPhotoDoc.KeyPhoto = tblRecord.RefNoPhotoDoc
/*Prey Data*/
INNER JOIN
tblPrey
ON
tblPrey.KeyPrey = tblRecord.RefNoPrey
INNER JOIN
tblPersons AS tblPersons_5
ON
tblPersons_5.KeyPersons = tblPrey.RefNoWriterPrey
/*Scat Data*/
INNER JOIN
tblScat
ON
tblScat.KeyScat = tblRecord.RefNoScat
INNER JOIN
tblPersons AS tblPersons_6
ON
tblPersons_6.KeyPersons = tblScat.RefNoWriterScat
/*Sighting Data*/
INNER JOIN
tblSighting
ON
tblSighting.KeySigthing = tblRecord.RefNoSighting
INNER JOIN
tblAnimal
ON
tblAnimal.KeyAnimal = tblSighting.RefNoAnimal
INNER JOIN
tblPersons AS tblPersons_2
ON
tblPersons_2.KeyPersons = tblSighting.RefNoWriterSight
/*Territory Name Data*/
INNER JOIN
tblTerritoryName
ON
tblTerritoryName.KeyTerritoryName = tblRecord.RefNoTerritoryName
/*Track Data*/
INNER JOIN
tblTrack
ON
tblTrack.KeyTrack = tblRecord.RefNoTrack
INNER JOIN
tblPersons AS tblPersons_7
ON
tblPersons_7.KeyPersons = tblTrack.RefNoWriterTrack
/*Urin Blood Data*/
INNER JOIN
tblUrinBlood
ON
tblUrinBlood.KeyUrinBlood = tblRecord.RefNoUrinBlood
INNER JOIN
tblPersons AS tblPersons_8
ON
tblPersons_8.KeyPersons = tblUrinBlood.RefNoWriterUrinBlood
/*UV Number Data*/
INNER JOIN
tblUVNumber
ON
tblUVNumber.KeyUVNo = tblRecord.RefNoUVNo
/*Validation Data*/
INNER JOIN
tblValidate
ON
tblValidate.KeyValidate = tblRecord.RefNoValidate
INNER JOIN
tblValidateSpecies
ON
tblValidateSpecies.KeyValidateSpecies = tblValidate.RefNoValSpecies
/*Pack Data*/
INNER JOIN
tblPack
ON
tblPack.KeyPack = tblValidate.RefNoPack
INNER JOIN
tblIndividual
ON
tblIndividual.KeyIndividual = tblValidate.RefNoIndi
/*Den Data*/
INNER JOIN
tblDen
ON
tblDen.KeyDen = tblRecord.RefNoDen
INNER JOIN
tblPersons AS tblPersons_9
ON
tblDen.RefNoWriterDen = tblPersons_9.KeyPersons
WHERE
(
tblRecord.RecRecordNumber like [Formularer]![frmSearchGeneral].[FindRecord] & "*"
AND tblUVNumber.UVNo Like [Formularer]![frmSearchGeneral].[FindUV] & "*"
AND tblRecord.RecDate Between
IIf([Forms]![frmSearchGeneral].[FindDateStart] Is Null ,#1/1/1000# ,[Forms]![frmSearchGeneral].[FindDateStart]
And IIf([Forms]![frmSearchGeneral].[FindDateEnd] Is Null,#12/31/9999#,[Forms]![frmSearchGeneral].[FindDateEnd]
AND tblPersons.PerFullName Like [Formularer]![frmSearchGeneral].[FindPerson] & "*"
AND tblPersons.PerOfficielObserver Like [Formularer]![frmSearchGeneral].[FindOfficial] & "*"
AND tblLocation.LocCountry Like [Formularer]![frmSearchGeneral].[FindCountry] & "*"
AND tblLocation.LocProvince Like [Formularer]![frmSearchGeneral].[FindProvince] & "*"
AND tblLocation.LocMuncipality Like [Formularer]![frmSearchGeneral].[FindMuncipality] & "*"
AND tblLocation.LocNearestTown Like [Formularer]![frmSearchGeneral].[FindNearestTown] & "*"
AND tblLocation.LocAreaName Like [Formularer]![frmSearchGeneral].[FindAreaName] & "*"
AND tblFieldTrip.FiTPathNumber Like [Formularer]![frmSearchGeneral].[FindTrackNo] & "*"
AND tblValidate.ValSCALP Like [Formularer]![frmSearchGeneral].[FindSCALP] & "*"
AND tblRecord.RecValidateYes Like (IIf([Formularer]![frmSearchGeneral].[FindValidate]=Yes ,[Formularer]![frmSearchGeneral].[FindValidate] ,"*")
AND tblRecord.RecScatYes Like IIf([Formularer]![frmSearchGeneral].[FindScat]=Yes ,[Formularer]![frmSearchGeneral].[FindScat] ,"*")
AND tblRecord.RecPreyYes Like IIf([Formularer]![frmSearchGeneral].[FindPrey]=Yes,[Formularer]![frmSearchGeneral].[FindPrey],"*")
AND tblRecord.RecOtherDNAYes Like IIf([Formularer]![frmSearchGeneral].[FindOtherDNA]=Yes,[Formularer]![frmSearchGeneral].[FindOtherDNA] ,"*")
AND tblRecord.RecSightingYes Like IIf([Formularer]![frmSearchGeneral].[FindSighting]=Yes ,[Formularer]![frmSearchGeneral].[FindSighting],"*")
AND tblRecord.RecTrackYes Like IIf([Formularer]![frmSearchGeneral].[FindTrack]=Yes,[Formularer]![frmSearchGeneral].[FindTrack] ,"*")
AND tblRecord.RecHowlYes Like IIf([Formularer]![frmSearchGeneral].[FindHowl]=Yes,[Formularer]![frmSearchGeneral].[FindHowl] ,"*")
AND tblRecord.RecUrinBloodYes Like IIf([Formularer]![frmSearchGeneral].[FindUrinBlood]=Yes,[Formularer]![frmSearchGeneral].[FindUrinBlood] ,"*")
AND tblRecord.RecCameraYes Like IIf([Formularer]![frmSearchGeneral].[FindCamera]=Yes,[Formularer]![frmSearchGeneral].[FindCamera] ,"*")
AND tblValidate.ValInsideWolfZone Like IIf([Formularer]![frmSearchGeneral].[FindWolfZone]=Yes,[formularer]![frmSearchGeneral].[FindWolfZone] ,"*")
AND tblValidate.RefNoValSpecies Like [Formularer]![frmSearchGeneral].[FindValidateSpecies] & "*"
AND tblPack.PackName Like [Formularer]![frmSearchGeneral].[FindPack] & "*"
AND tblIndividual.Individual Like [Formularer]![frmSearchGeneral].[FindIndividual] & "*"
AND tblTerritoryName.TerritoryName Like [formularer]![frmSearchGeneral].[FindTerritory] & "*"
AND tblRecord.Deactivated =False
AND Year[RecDate] =[Forms]![frmSearchGeneral].[FindYearSpecific]
)
OR
(
tblRecord.RecRecordNumber Like [Formularer]![frmSearchGeneral].[FindRecord] & "*"
AND tblUVNumber.UVNo Like [Formularer]![frmSearchGeneral].[FindUV] & "*"
AND tblRecord.RecDate Between
IIf([Forms]![frmSearchGeneral].[FindDateStart] Is Null,#1/1/1000# ,[Forms]![frmSearchGeneral].[FindDateStart])
And IIf([Forms]![frmSearchGeneral].[FindDateEnd] Is Null,#12/31/9999# ,[Forms]![frmSearchGeneral].[FindDateEnd])
AND tblPersons.PerFullName Like [Formularer]![frmSearchGeneral].[FindPerson] & "*"
AND tblPersons.PerOfficielObserver Like [Formularer]![frmSearchGeneral].[FindOfficial] & "*"
AND tblLocation.LocCountry Like [Formularer]![frmSearchGeneral].[FindCountry] & "*"
AND tblLocation.LocProvince Like [Formularer]![frmSearchGeneral].[FindProvince] & "*"
AND tblLocation.LocMuncipality Like [Formularer]![frmSearchGeneral].[FindMuncipality] & "*"
AND tblLocation.LocNearestTown Like [Formularer]![frmSearchGeneral].[FindNearestTown] & "*"
AND tblLocation.LocAreaName Like [Formularer]![frmSearchGeneral].[FindAreaName] & "*"
AND tblFieldTrip.FiTPathNumber Like [Formularer]![frmSearchGeneral].[FindTrackNo] & "*"
AND tblValidate.ValSCALP Like [Formularer]![frmSearchGeneral].[FindSCALP] & "*"
AND tblRecord.RecValidateYes Like IIf([Formularer]![frmSearchGeneral].[FindValidate]=Yes ,[Formularer]![frmSearchGeneral].[FindValidate],"*")
AND tblRecord.RecScatYes Like IIf([Formularer]![frmSearchGeneral].[FindScat]=Yes ,[Formularer]![frmSearchGeneral].[FindScat] ,"*")
AND tblRecord.RecPreyYes Like IIf([Formularer]![frmSearchGeneral].[FindPrey]=Yes ,[Formularer]![frmSearchGeneral].[FindPrey] ,"*")
AND tblRecord.RecOtherDNAYes Like IIf([Formularer]![frmSearchGeneral].[FindOtherDNA]=Yes ,[Formularer]![frmSearchGeneral].[FindOtherDNA] ,"*")
AND tblRecord.RecSightingYes Like IIf([Formularer]![frmSearchGeneral].[FindSighting]=Yes ,[Formularer]![frmSearchGeneral].[FindSighting] ,"*")
AND tblRecord.RecTrackYes Like IIf([Formularer]![frmSearchGeneral].[FindTrack]=Yes ,[Formularer]![frmSearchGeneral].[FindTrack] ,"*")
AND tblRecord.RecHowlYes Like IIf([Formularer]![frmSearchGeneral].[FindHowl]=Yes ,[Formularer]![frmSearchGeneral].[FindHowl] ,"*")
AND tblRecord.RecUrinBloodYes Like IIf([Formularer]![frmSearchGeneral].[FindUrinBlood]=Yes ,[Formularer]![frmSearchGeneral].[FindUrinBlood] ,"*")
AND tblRecord.RecCameraYes Like IIf([Formularer]![frmSearchGeneral].[FindCamera]=Yes ,[Formularer]![frmSearchGeneral].[FindCamera] ,"*")
AND tblValidate.ValInsideWolfZone Like IIf([Formularer]![frmSearchGeneral].[FindWolfZone]=Yes ,[formularer]![frmSearchGeneral].[FindWolfZone] ,"*")
AND tblValidate.RefNoValSpecies Like [Formularer]![frmSearchGeneral].[FindValidateSpecies] & "*"
AND tblPack.PackName Like [Formularer]![frmSearchGeneral].[FindPack] & "*"
AND tblIndividual.Individual Like [Formularer]![frmSearchGeneral].[FindIndividual] & "*"
AND tblTerritoryName.TerritoryName Like [formularer]![frmSearchGeneral].[FindTerritory] & "*"
AND tblRecord.Deactivated =False
AND Year[RecDate] Between
IIf([Forms]![frmSearchGeneral].[FindYearStart] Is Null,#1/1/1000# ,[Forms]![frmSearchGeneral].[FindYearStart])
And IIf([Forms]![frmSearchGeneral].[FindYearEnd] Is Null,#12/31/9999# ,[Forms]![frmSearchGeneral].[FindYearEnd])
AND [Forms]![frmSearchGeneral].[FindYearSpecific] Is Null
);
这不能解决Access的复杂性问题,但确实可以解决人类问题。
我要做的是注意我在您的联接中所做的注释,并为这些注释中的每一个进行子查询,然后执行以下操作。在一个最终查询中将所有这些子查询连接在一起。
SELECT fields, you, need
FROM tblRecord
/*Den Data*/
INNER JOIN
tblDen
ON
tblDen.KeyDen = tblRecord.RefNoDen
INNER JOIN
tblPersons AS tblPersons_9
ON
tblDen.RefNoWriterDen = tblPersons_9.KeyPersons