SQLTeam.com | Weblogs | Forums

Invalid Column Name in Update Statement


I'm getting an error on the line that has the "case" statement. The error is:

Invalid column name 'ProductTransactionStatusCode'.

I have confirmed that the column name, which is of VARCHAR type, is in fact in the table ProductInformation_W

The SQL 2008 statement is:

ProductInformation.CollectionDate = h.CollectionDate
,ProductInformation.ExpirationDate = CONVERT(DATETIME, LEFT(CONVERT(VARCHAR, h.ExpirationDate, 120), 10) + ' ' + h.ExpirationTime + ':00.000', 121)
,ProductInformation.CreationDate = h.CreationDate
,ProductInformation.CollectionLocationCode = h.CollectionLocationCode
,ProductInformation.ProductTypeCode = h.ProductTypeCode
,ProductInformation.ProductStatusCode = h.ProductStatusCode
,ProductInformation.InventoryClassCode = h.InventoryClassCode
,ProductInformation.StockStateCode = h.StockStateCode
,ProductInformation.Imported = h.Imported
,ProductInformation.Exported = (Case When h.ProductTransactionStatusCode In ('048', '051') Then h.Exported Else p.ProductTransactionStatusCode End)
,ProductInformation.ProcessingLocationCode = h.ProcessingLocationCode
,ProductInformation.RunDateTime = getdate()
ProductInformation p
ProductInformation_W h
p.UnitNumber = h.UnitNumber AND p.ProductCode = h.ProductCode AND p.Suffix = h.Suffix


You have h.ProductTransactionStatusCode and p.ProductTransactionStatusCode in the query in the case expression. You verified that it is in the ProductInformation_W table, which is aliased to h. But is there a column by the same name in ProductInformation table, which is aliased to p as well?


Good call! No there isn't, in fact - thanks!


And the field actually should be p.Exported.