C
croy
This Union query has me stumped. The SQL for each of the
two querys runs fine on their own, but together in this
union the query runs, shows the first screen of data, and
then dumps "Data mismatch" in a dialog. I'm beginning to
suspect that the problem may not be data mismatch, but I
can't figure out what it is.
Here's the SQL (badly wrapped):
SELECT
IIf([GeoLocDE]="10.1","10.1",IIf([GeoLocDE]="11","11",IIf([GeoLocDE]="11.1","11",IIf([GeoLocDE]="11.2","11",IIf([GeoLocDE]="12.1","12.1",Int([GeoLocDE]))))))
AS Loc, tblIvSurv.SurveyDate, tblIvDetail.RiverMile,
tblMethod.MethDE, tblIvDetail.NumberAnglers,
tblIvDetail.HrsFished, tblIvDetail.SpeciesId AS Target,
tblIvDetail.Done, tblIvDetail.ZipCode,
IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE])))))
AS Spp, tblCatch.Kept, tblCatch.Released
FROM tblRiver INNER JOIN (tblMethod INNER JOIN (tblSpecies
RIGHT JOIN (((tblGeoLoc INNER JOIN tblIvSurv ON
tblGeoLoc.GeoLocId = tblIvSurv.GeoLocId) INNER JOIN
tblIvDetail ON tblIvSurv.IvSurvId = tblIvDetail.IvSurvId)
LEFT JOIN tblCatch ON tblIvDetail.IvDetId =
tblCatch.IvDetId) ON tblSpecies.SpeciesId =
tblCatch.SpeciesId) ON tblMethod.MethodId =
tblIvDetail.MethodId) ON tblRiver.RivId = tblGeoLoc.RivId
WHERE (((tblIvSurv.SurveyDate)<#7/1/2009#) AND
((IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="CS"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="RT"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="SH"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="SB"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="AS"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="ST"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="--")
AND ((tblIvSurv.IvTypeId)=1) AND ((tblRiver.RiverDE)="SAC"
Or (tblRiver.RiverDE)="AM" Or (tblRiver.RiverDE)="FR"))
UNION ALL SELECT PhysDat.Section, PhysDat.SurveyDate,
IvDat.RiverMile, IIf([Method]="B","1","2") AS Mth,
IvDat.NumberAnglers, IvDat.HrsFished,
IIf([TargetSpecies]="KS","CS",[TargetSpecies]) AS Tgt,
IvDat.Done, IvDat.ZipCode,
IIf([OrganismCode]="KS","CS",[OrganismCode]) AS Spp,
nz([Kept],0) AS K, nz([Released],0) AS Rel
FROM PhysDat LEFT JOIN (IvDat LEFT JOIN CatchNum ON
IvDat.InterviewNumRowID = CatchNum.InterviewNumRowID) ON
PhysDat.PhysDatId = IvDat.PhysDatId
WHERE (((PhysDat.Section)<15) AND
((IIf([OrganismCode]="KS","CS",[OrganismCode]))="CS" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="RT" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="SH" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="SB" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="AS" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="ST"));
two querys runs fine on their own, but together in this
union the query runs, shows the first screen of data, and
then dumps "Data mismatch" in a dialog. I'm beginning to
suspect that the problem may not be data mismatch, but I
can't figure out what it is.
Here's the SQL (badly wrapped):
SELECT
IIf([GeoLocDE]="10.1","10.1",IIf([GeoLocDE]="11","11",IIf([GeoLocDE]="11.1","11",IIf([GeoLocDE]="11.2","11",IIf([GeoLocDE]="12.1","12.1",Int([GeoLocDE]))))))
AS Loc, tblIvSurv.SurveyDate, tblIvDetail.RiverMile,
tblMethod.MethDE, tblIvDetail.NumberAnglers,
tblIvDetail.HrsFished, tblIvDetail.SpeciesId AS Target,
tblIvDetail.Done, tblIvDetail.ZipCode,
IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE])))))
AS Spp, tblCatch.Kept, tblCatch.Released
FROM tblRiver INNER JOIN (tblMethod INNER JOIN (tblSpecies
RIGHT JOIN (((tblGeoLoc INNER JOIN tblIvSurv ON
tblGeoLoc.GeoLocId = tblIvSurv.GeoLocId) INNER JOIN
tblIvDetail ON tblIvSurv.IvSurvId = tblIvDetail.IvSurvId)
LEFT JOIN tblCatch ON tblIvDetail.IvDetId =
tblCatch.IvDetId) ON tblSpecies.SpeciesId =
tblCatch.SpeciesId) ON tblMethod.MethodId =
tblIvDetail.MethodId) ON tblRiver.RivId = tblGeoLoc.RivId
WHERE (((tblIvSurv.SurveyDate)<#7/1/2009#) AND
((IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="CS"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="RT"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="SH"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="SB"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="AS"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="ST"
Or
(IIf([SpeciesDE]="SHCL","SH",IIf([SpeciesDE]="SHU","SH",IIf([SpeciesDE]="RTCL","RT",IIf([SpeciesDE]="RTU","RT",IIf(IsNull([SpeciesDE]),"--",[SpeciesDE]))))))="--")
AND ((tblIvSurv.IvTypeId)=1) AND ((tblRiver.RiverDE)="SAC"
Or (tblRiver.RiverDE)="AM" Or (tblRiver.RiverDE)="FR"))
UNION ALL SELECT PhysDat.Section, PhysDat.SurveyDate,
IvDat.RiverMile, IIf([Method]="B","1","2") AS Mth,
IvDat.NumberAnglers, IvDat.HrsFished,
IIf([TargetSpecies]="KS","CS",[TargetSpecies]) AS Tgt,
IvDat.Done, IvDat.ZipCode,
IIf([OrganismCode]="KS","CS",[OrganismCode]) AS Spp,
nz([Kept],0) AS K, nz([Released],0) AS Rel
FROM PhysDat LEFT JOIN (IvDat LEFT JOIN CatchNum ON
IvDat.InterviewNumRowID = CatchNum.InterviewNumRowID) ON
PhysDat.PhysDatId = IvDat.PhysDatId
WHERE (((PhysDat.Section)<15) AND
((IIf([OrganismCode]="KS","CS",[OrganismCode]))="CS" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="RT" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="SH" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="SB" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="AS" Or
(IIf([OrganismCode]="KS","CS",[OrganismCode]))="ST"));