DawnTreader formulated on Monday :
It happens that DawnTreader formulated :
Hello
i have a few tables that i need to know the completeness of records
based on certain fields. i am wondering if there is a way to query
each of those tables easily based on a list of field names in a table
to see if the fields are null or default data.
i am thinking i will need some code, but i am wondering if any one has
a simple query solution to this.
thanks in advance.
This is Easy - Peasy. Hint! Nulls Propagate! So...
SELECT PrimaryID, [Column1]+[Column2]+[Column3] AS MissingFields
FROM YourTable
Where ([Column1]+[Column2]+[Column3]) is Null
Show all of the Rows that are missing data in one or more columns.
Note I am using the + not the &.
Rdub
hmmm.
if, as you say, nulls propagate then if only one field is null your
missingfields will turn null. i need to know how many are null.
something akin to count if null. or count if not null. i want to know
how much out of a 100% a record is complete or missing. your
suggestion gives me an idea, but i need something more.
thanks for the reply. will post what i come up with.
Select * From YourTable Where
PrimaryID in( SELECT PrimaryID FROM YourTable Where
([Column1]+[Column2]+[Column3]) is Null)
Returns all of the Rows where at least one of the Columns was null
Here is what i am using on one table:
SELECT tblProductList.ProductID, tblProductList.ProductTypeID,
tblProductList.SerialNumber, IIf([CustomerOrder] Is Null,0,1) AS CO,
IIf([DateShipped] Is Null,0,1) AS DS, IIf([DateCommissioned] Is Null,
0,1) AS DC, IIf([WarrantyMonths] Is Null,0,1) AS WM,
IIf([WarrantyShippedMonths] Is Null,0,1) AS WSM,
IIf([ProductTypeID]="Compressor",IIf([WarrantyHours] Is Null,0,1),1)
AS WH, IIf([WorkOrder] Is Null,0,1) AS WO, IIf([SerialNumber] Is Null,
0,1)+IIf([CustomerOrder] Is Null,0,1)+IIf([DateShipped] Is Null,
0,1)+IIf([DateCommissioned] Is Null,0,1)+IIf([WarrantyMonths] Is Null,
0,1)+IIf([WarrantyShippedMonths] Is Null,
0,1)+IIf([ProductTypeID]="Compressor",IIf([WarrantyHours] Is Null,0,1),
1)+IIf([WorkOrder] Is Null,0,1)+IIf([ModelNumber] Is Null,0,1) AS
ProductCompleteness
FROM tblProductList
WHERE (((tblProductList.DateDeleted) Is Null))
GROUP BY tblProductList.ProductID, tblProductList.ProductTypeID,
tblProductList.SerialNumber, IIf([CustomerOrder] Is Null,0,1),
IIf([DateShipped] Is Null,0,1), IIf([DateCommissioned] Is Null,0,1),
IIf([WarrantyMonths] Is Null,0,1), IIf([WarrantyShippedMonths] Is Null,
0,1), IIf([ProductTypeID]="Compressor",IIf([WarrantyHours] Is Null,
0,1),1), IIf([WorkOrder] Is Null,0,1), IIf([SerialNumber] Is Null,
0,1)+IIf([CustomerOrder] Is Null,0,1)+IIf([DateShipped] Is Null,
0,1)+IIf([DateCommissioned] Is Null,0,1)+IIf([WarrantyMonths] Is Null,
0,1)+IIf([WarrantyShippedMonths] Is Null,
0,1)+IIf([ProductTypeID]="Compressor",IIf([WarrantyHours] Is Null,0,1),
1)+IIf([WorkOrder] Is Null,0,1)+IIf([ModelNumber] Is Null,0,1)
ORDER BY tblProductList.SerialNumber;
but here is what i have going on another table:
SELECT subdatatblCompressor.CompressorID,
subdatatblCompressor.ProductID, subdatatblCompressor.ProductTypeID,
IIf([CBASubAssemblyPartNumber] Is Null,0,1) AS CBASAPN,
IIf([CompressorPartNumber] Is Null,0,1) AS CPN, IIf([CompressorTypeID]
Is Null,0,IIf([CompressorTypeID]=18,0,1)) AS CTID, IIf([BlockTypeID]
Is Null,0,IIf([BlockTypeID]=4,0,1)) AS BTID, IIf([CrankshaftTypeID] Is
Null,0,IIf([CrankshaftTypeID]=3,0,1)) AS CSTID,
IIf([InletGasTemp]>0,1,0) AS IGT, IIf([InletPressure]>0,1,0) AS IP,
IIf([FlowRate]>0,1,0) AS FR, IIf([DischargePressure]>0,1,0) AS DP,
IIf([DischargeTemp]>0,1,0) AS DT, IIf([LowSuctionAlarm]>0,1,0) AS LSA,
IIf([HighSuctionAlarm]>0,1,0) AS HSA, IIf([StartPressure]>0,1,0) AS
SP, IIf([StopPressure]>0,1,0) AS STPP, IIf([CoolingMethod] Is Null,
0,IIf([CoolingMethod]="Default",0,1)) AS CM,
IIf([Stages]>=1,IIf([1stStageConfig] Is Null,0,1),0) AS FSC,
IIf([Stages]>=2,IIf([2ndStageConfig] Is Null,0,1),0) AS SSC,
IIf([Stages]>=3,IIf([3rdStageConfig] Is Null,0,1),0) AS TSC,
IIf([Stages]>=4,IIf([4thStageConfig] Is Null,0,1),0) AS FthSC,
IIf([Stages]>=5,IIf([5thStageConfig] Is Null,0,1),0) AS FFthSC,
IIf([PriorityPanelTypeID] Is Null,0,IIf([PriorityPanelTypeID]=1,0,1))
AS PPTID, IIf([PLCTypeID] Is Null,0,IIf([PLCTypeID]=5,0,1)) AS PLCTID,
IIf([ScreenTypeID] Is Null,0,IIf([ScreenTypeID]=5,0,1)) AS STID,
IIf([BlockQty] Is Null,0,IIf([BlockQty]=0,0,1)) AS BQTY,
IIf([PLCPanelSerial] Is Null,0,1) AS PLCPS,
IIf([MotorControlPanelSerial] Is Null,0,1) AS MCCS,
IIf([PriorityControlPanelSerial] Is Null,0,1) AS PCPS,
IIf([CoolerAssemblyPartNumber] Is Null,0,1) AS CAPN,
IIf([CoolerAssemblySerial] Is Null,0,1) AS CAS,
IIf([Stages]>=1,IIf([1stStagePSI] Is Null,0,IIf([1stStagePSI]=0,0,1)),
0) AS FSPSI, IIf([Stages]>=2,IIf([2ndStagePSI] Is Null,
0,IIf([2ndStagePSI]=0,0,1)),0) AS SSPSI,
IIf([Stages]>=3,IIf([3rdStagePSI] Is Null,0,IIf([3rdStagePSI]=0,0,1)),
0) AS TSPSI, IIf([Stages]>=4,IIf([4thStagePSI] Is Null,
0,IIf([4thStagePSI]=0,0,1)),0) AS FthSPSI,
IIf([Stages]>=5,IIf([5thStagePSI] Is Null,0,IIf([5thStagePSI]=0,0,1)),
0) AS FFthSPSI, IIf([Stages]>=1,IIf([1stStageTemp] Is Null,
0,IIf([1stStageTemp]=0,0,1)),0) AS FST,
IIf([Stages]>=2,IIf([2ndStageTemp] Is Null,
0,IIf([2ndStageTemp]=0,0,1)),0) AS SST,
IIf([Stages]>=3,IIf([3rdStageTemp] Is Null,
0,IIf([3rdStageTemp]=0,0,1)),0) AS TST,
IIf([Stages]>=4,IIf([4thStageTemp] Is Null,
0,IIf([4thStageTemp]=0,0,1)),0) AS FthST,
IIf([Stages]>=5,IIf([5thStageTemp] Is Null,
0,IIf([5thStageTemp]=0,0,1)),0) AS FFthST, IIf([BlockRPM] Is Null,
0,IIf([BlockRPM]=0,0,1)) AS BRPM, IIf([DriveTypeID] Is Null,
0,IIf([DriveTypeID]=1,0,1)) AS DTID, IIf([GasEngineRPM] Is Null,
0,IIf([GasEngineRPM]=0,0,1)) AS GERPM, IIf([GasEngineSerialNumber] Is
Null,0,1) AS GESN, IIf([EngineArrangementNumber] Is Null,0,1) AS EAN,
IIf([GasEngineModelNumber] Is Null,0,1) AS GEMN,
IIf([EngineStarterLubeLevel] Is Null,0,1) AS ESLL, IIf([EngineOilPSI]
Is Null,0,IIf([EngineOilPSI]=0,0,1)) AS EOPSI,
IIf([EngineWaterJacketTempurature] Is Null,
0,IIf([EngineWaterJacketTempurature]=0,0,1)) AS EWJT,
IIf([EngineWaterJacketCoolant] Is Null,
0,IIf([EngineWaterJacketCoolant]=0,0,1)) AS EWJC,
IIf([GasEngineHorsePower] Is Null,0,IIf([GasEngineHorsePower]=0,0,1))
AS GEHP, IIf([ElectricRPM] Is Null,0,IIf([ElectricRPM]=0,0,1)) AS
ERPM, IIf([ElectricMotorSerialNumber] Is Null,0,1) AS EMSN,
IIf([ElectricMotorHorsePower] Is Null,0,1) AS EMHP,
subdatatblCompressor.ThermalProtectionID,
subdatatblCompressor.Voltage, subdatatblCompressor.Hz,
subdatatblCompressor.CrankcaseStyleID, subdatatblCompressor.SealType,
subdatatblCompressor.OilHeater, subdatatblCompressor.TKNumber,
subdatatblCompressor.Stages, subdatatblCompressor.GasCoolingSystem,
subdatatblCompressor.MinFlowCapacity,
subdatatblCompressor.MaxFlowCapacity,
subdatatblCompressor.InletPulsationBottles,
subdatatblCompressor.DischargePulsationBottles,
subdatatblCompressor.FlowRateGGE,
subdatatblCompressor.RemoteMonitoring,
subdatatblCompressor.FlowRateKgMin
FROM subdatatblCompressor;
and i havent finished yet. in the end i need one column that will
calculate the total as i did with the first example.
is there a way to use code to do this?- Hide quoted text -
- Show quoted text -