DMT Error: A Valid To Warehouse is required

Another one just for the knowledge base - a problem I have tripped on many times and hopefully can help someone else with.

(Actually, it’s just that I selfishly want to see this next time I search for this issue).

I have to return material from several thousand jobs where excess material was issued. My usual methodology is to run a query against Erp.JobClosingLog after running auto job closing (pardon my Steve-SQL syntax, it works for me :slightly_smiling_face:):

select
	'RDCAN' Company,
	l.JobNum FromJobNum,
	l.MtlPartNum PartNum,
	l.AssemblySeq FromAssemblySeq,
	l.JobSeq FromJobSeq,
	l.ActQuantity - l.EstQuantity TranQty,
	w.WarehouseCode ToWarehouseCode,
	w.PrimBin ToBinNum

from
	Production.erp.JobClosinglog l
	inner join Production.erp.JobHead h
		on h.JobNum = l.JobNum
	inner join Production.erp.PlantWhse w
		on w.PartNum = l.MtlPartNum
		and w.Plant = h.Plant
		and w.WarehouseCode like '%001'
where
	l.AuditSource = 'JobCompletion'
	and l.EstQuantity < l.ActQuantity

This generates my DMT, which uploads happily. Water begins to quench the fire, fire begins to burn the stick, stick begins to beat the dog, dog begins to bite the pig, pig jumps over the stile, and we all get home for supper.

However, for several hundred jobs, once in a while I get an error “A Valid To Warehouse is Required”.

Long story short, column placement does nothing, checking for trailing spaces ditto, nothing helps. Usually, I end up doing this process manually, and this time on a whim I added a “Plant” column.

It was too late for supper, but at least it worked.