Sales by State reporting

Caleb,

This should be Invcdtl.shiptonum (not shiptocustnum)

when InvcDtl.UseOTS = ‘1’ then InvcDtl.OTSState
when InvcDtl.ShipToCustNum > ‘’ then ShipTo.State
else Customer.State
end) as [Calculated_TheShipTo]
from Erp.InvcDtl as InvcDtl
left outer join Erp.ShipTo as ShipTo on
InvcDtl.Company = ShipTo.Company
And
InvcDtl.CustNum = ShipTo.CustNum
And
InvcDtl.ShipToNum = ShipTo.ShipToNum

inner join Erp.Customer as Customer on
InvcDtl.Company = Customer.Company
And
InvcDtl.CustNum = Customer.CustNum

inner join Erp.InvcHead as InvcHead on
Customer.Company = InvcHead.Company
And
Customer.CustNum = InvcHead.CustNum
and ( InvcHead.Posted = 1 )