Code:
INSERTINTO TblBlocks ( s_Generation, [Count], Block, BlockUnitCodeOLD,
BlockUnitCode, Establishment, EstablishmentDate, Maintenance, MaintenanceDate,
Location, PlantIDScion, PlantIDRoot, YearPlanted, BlockStatus, Trees,
Trees_Balance, ReWorked, OtherVirus, Vlamsikte, AmPLP, EurPLP, Clold, Slold,
Pnrsold, Pdvold, Gvflold, Apmvold, Gvlrold, TtFlower, TtFruit, SubYear,
ResubYear, Supplier, PathLetter, StatusReason, BlockType, OriginScion,
OriginRoot, OrgBlockTypeScion, OrgBlockTypeRoot, CombinedBlockType,
Contract, ConttractNo, ContractType, [Date Signed], LabelType, CultivarNoName,
BlockAspect, SampleDate, TestDate, Virus, TestResult, TestComment, RefNo,
[Prefered BLock], AM, AMDate, CommentAM, AGC, AGCDate, CommentAGC, AP, APDate,
CommentAP, AR, ARDate, CommentAR, BC, BCDate, CommentBC, CF, CFDate,
CommentCF, CL, CLDate, CommentCL, CR, CRDate, CommentCR, FL, FLDate,
CommentFL, GCB, GCBDate, CommentGCB, GD, GDDAte, CommentGD, GF, GFDate,
CommentGF, GFL, GFLDate, CommentGFL, GS, GSDate, CommentGS, LP, LPDate,
CommentLP, LR, LRDate, CommentLR, LRC, LRCDate, CommentLRC, NS, NSDate,
CommentNS, PD, PDDate, CommentPD, PL, PLDate, CommentPL, PKRR, PKRRDate,
CommentPKRR, PKRV, PKRVDate, CommentPKRV, PR, PRDate, CommentPR, PRPM,
PRPMDate, CommentPRPM, PDW, PDWDate, CommentPDW, QS, QSDate, CommentQS, RL,
RLDate, CommentRL, RR, RRDate, CommentRR, RW, RWDate, CommentRW, SB, SBDate,
CommentSB, SD, SDDate, CommentSD, SG, SGDate, CommentSG, SP, SPDate,
CommentSP, SR, SRDate, CommentSR, SS, SSDate, CommentSS, TL, TLDate,
CommentTL, TP, TPDate, CommentTP, VS, VSDate, CommentVS, VY, VYDate,
CommentVY, YB, YBDate, CommentYB, GVA, GVADate, CommentGVA, GVB, GVBDate,
CommentGVB, PM, PMDate, CommentPM, NoVirus, NoVirusDate, CommentNoVirus,
[Date Created], SelectBox, GPS_Block, Nursery_Nr, Graft_Ref_Nr
)
SELECT
IIF(IsNumeric(B.s_Generation), Val(B.s_Generation), 0) AS s_Generation_Default_Zero,
B.[Count], B.Block,
Nz(B.BlockUnitCodeOLD, "") AS BlockUnitCodeOLD_Safe, -- Changed to empty string if NULL/blank
B.BlockUnitCode, B.Establishment,
IIF(Nz(B.EstablishmentDate, "")="", NULL, CDbl(CDate(B.EstablishmentDate))) AS New_EstablishmentDate,
B.Maintenance,
IIF(Nz(B.MaintenanceDate, "")="", NULL, CDate(B.MaintenanceDate)) AS New_MaintenanceDate,
B.Location, B.PlantIDScion, B.PlantIDRoot, B.YearPlanted, B.BlockStatus, B.Trees,
B.Trees_Balance, B.ReWorked, B.OtherVirus, B.Vlamsikte, B.AmPLP, B.EurPLP, B.Clold, B.Slold,
B.Pnrsold, B.Pdvold, B.Gvflold, B.Apmvold, B.Gvlrold, B.TtFlower, B.TtFruit, B.SubYear,
B.ResubYear, B.Supplier,
IIF(Nz(B.PathLetter, "")="", NULL, CDate(B.PathLetter)) AS New_PathLetter,
B.StatusReason, B.BlockType, B.OriginScion,
B.OriginRoot, B.OrgBlockTypeScion, B.OrgBlockTypeRoot, B.CombinedBlockType,
B.Contract, B.ConttractNo, B.ContractType, B.[Date Signed], B.LabelType, B.CultivarNoName,
B.BlockAspect,
IIF(Nz(B.SampleDate, "")="", NULL, CDate(B.SampleDate)) AS New_SampleDate,
IIF(Nz(B.TestDate, "")="", NULL, CDate(B.TestDate)) AS New_TestDate,
B.Virus, B.TestResult, B.TestComment, B.RefNo,
B.[Prefered BLock], B.AM, B.AMDate, B.CommentAM, B.AGC, B.AGCDate, B.CommentAGC, B.AP, B.APDate,
B.CommentAP, B.AR, B.ARDate, B.CommentAR, B.BC, B.BCDate, B.CommentBC, B.CF, B.CFDate,
B.CommentCF, B.CL, B.CLDate, B.CommentCL, B.CR, B.CRDate, B.CommentCR, B.FL, B.FLDate,
B.CommentFL, B.GCB, B.GCBDate, B.CommentGCB, B.GD, B.GDDAte, B.CommentGD, B.GF, B.GFDate,
B.CommentGF, B.GFL,
IIF(Nz(B.GFLDate, "")="", NULL, CDate(B.GFLDate)) AS New_GFLDate,
B.CommentGFL, B.GS, B.GSDate, B.CommentGS, B.LP, B.LPDate, B.CommentLP, B.LR,
IIF(Nz(B.LRDate, "")="", NULL, CDate(B.LRDate)) AS New_LRDate,
B.CommentLR, B.LRC, B.LRCDate, B.CommentLRC, B.NS, B.NSDate, B.CommentNS, B.PD, B.PDDate, B.CommentPD, B.PL, B.PLDate, B.CommentPL, B.PKRR, B.PKRRDate,
B.CommentPKRR, B.PKRV, B.PKRVDate, B.CommentPKRV, B.PR, B.PRDate, B.CommentPR, B.PRPM,
B.PRPMDate, B.CommentPRPM, B.PDW, B.PDWDate, B.CommentPDW, B.QS, B.QSDate, B.CommentQS, B.RL,
B.RLDate, B.CommentRL, B.RR, B.RRDate, B.CommentRR, B.RW, B.RWDate, B.CommentRW, B.SB, B.SBDate,
B.CommentSB, B.SD, B.SDDate, B.CommentSD, B.SG, B.SGDate, B.CommentSG, B.SP, B.SPDate,
B.CommentSP, B.SR, B.SRDate, B.CommentSR, B.SS, B.SSDate, B.CommentSS, B.TL, B.TLDate,
B.CommentTL, B.TP, B.TPDate, B.CommentTP, B.VS, B.VSDate, B.CommentVS, B.VY, B.VYDate,
B.CommentVY, B.YB, B.YBDate, B.CommentYB, B.GVA, B.GVADate, B.CommentGVA, B.GVB, B.GVBDate,
B.CommentGVB, B.PM, B.PMDate, B.CommentPM, B.NoVirus, B.NoVirusDate, B.CommentNoVirus,
IIF(Nz(B.[Date Created], "")="", NULL, CDate(B.[Date Created])) AS New_DateCreated,
B.SelectBox, B.GPS_Block, B.Nursery_Nr, B.Graft_Ref_Nr
FROM Block14 AS B
WHERE B.[Count] = -1048492341 AND B.Block = '14';