Question : Error: FieldName is not valid in the context where it is used.

I'm running this query in Access...

INSERT INTO tblDemand
SELECT * FROM qryPassThrough

...to run a pass-through query that's sent to DB2.

The first part of qryPassThrough...

SELECT LOWES.T2398_IFM_FRC_VAL.T024_ITM_NBR, LOWES.T2398_IFM_FRC_VAL.T063_LCT_NBR, CASE WHEN SEN_BGN_WK_NBR<=SEN_END_WK_NBR THEN SEN_END_WK_NBR-SEN_BGN_WK_NBR+1 ELSE 52-SEN_BGN_WK_NBR+SEN_END_WK_NBR+1 END AS "Selling Weeks",  LOWES.T2355_SEN_PRL.WK1_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK2_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK3_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK4_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK5_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK6_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK7_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK8_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK9_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK10_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK11_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK12_BAS_IND_FCT+LOWES.T2355_SEN_PRL.WK13_BAS_IND_FCT AS "Q1 Sum of BIs", …

Any ideas what's causing the error?

Answer : Error: FieldName is not valid in the context where it is used.

Since Q1_SUM_OF_BIS is derived in the column list, I'm not aware of any capability to use it in the same column list.

Assuming that you want this in a single statement/query and you can't create VIEWs, you might need to use a CTE to generate your base level derived columns; then refer to those in the final SELECT column list.

Tom
Random Solutions  
 
programming4us programming4us