Stack Exchange
could you help me with nested CTE?
Could you help me to modify my code,I try to expline every line
 WITH C ( ItemCode, LineNum, U_XAM_PED_SIG, U_XAM_ADU_SIG,
 U_XAM_FECHA_SIG, DocEntry ) AS  (  SELECT T0.ItemCode, T0.LineNum,
 t0.U_XAM_PED_SIG, T0.U_XAM_ADU_SIG, t0.U_XAM_FECHA_SIG, t0.DocEntry
        FROM INV1 T0 INNER JOIN OITM T1 ON T1.ItemCode = T0.ItemCode        WHERE
 T0.DocEntry = @list_of_cols_val_tab_del                AND T1.ManBtchNum='Y'
        AND T0.BaseEntry IS NULL ),   D AS  ( SELECT T0.BatchNum, T0.InDate,
 T0.Located, T0.Quantity            FROM OIBT T0 INNER JOIN IBT1 T1 ON
 (T0.BatchNum = T1.BatchNum AND T1.WhsCode = T0.WhsCode  )          WHERE
 T1.BaseType = 13           AND T0.ItemCode = T1.ItemCode                       AND
 T0.ItemCode = C.ItemCode   ------ I want to call previous CTE (error)      
            AND T1.BaseLinNum = 0 )     UPDATE C SET U_XAM_PED_SIG = 
 U_XAM_PED_SIG+LEFT(REPLACE (D.BatchNum,' ','')+'              ',12)+',
 ',             U_XAM_ADU_SIG = U_XAM_ADU_SIG+LEFT(D.Located+'                 
 ',19)+',',             U_XAM_FECHA_SIG =
 U_XAM_FECHA_SIG+LEFT(CONVERT(nvarchar(30), D.InDate, 20)+'         
 ',10)+','          WHERE DocEntry = @list_of_cols_val_tab_del          AND LineNum
 = c.LineNum
 --- basically I want to concatenate the different rows and update a single field


Please format the code correctly. This can be done by selecting the code and pressing the {} button, or indenting each line of code with four spaces.

You can't update through a CTE -- or shouldn't even if you could. However, it doesn't look like you need a CTE at all. See if you can generate a result set that looks like this:
select  I.U_XAM_PED_SIG, I.U_XAM_ADU_SIG, I.U_XAM_FECHA_SIG, -- Existing data
        D.BatchNum, D.Located, D.InDate -- New Data, or part of it
FROM    INV1 I
JOIN    OITM TM
    ON  TM.ItemCode = I.ItemCode
    AND TM.ManBtchNum = 'Y'
JOIN    OIBT BT
    ON  BT.ItemCode = I.ItemCode
JOIN    IBT1 T1
    ON  T1.ItemCode = I.ItemCode
    AND T1.WhsCode  = BT.WhsCode
    AND T1.BaseLinNum = 0
    AND T1.BaseType = 13
WHERE   I.DocEntry = @list_of_cols_val_tab_del
    AND I.BaseEntry IS NULL;

I don't know how accurately I've deconstructed your query so play around with it. Once you get the existing data and the new data that will replace or be appended to it all on one row, then you can construct the update statement.
The exact syntax of that update statement will be DBMS-dependent. About the easiest will be SQL Server where you can replace the select with update/set:
UPDATE  I
    SET I.U_XAM_PED_SIG = I.U_XAM_PED_SIG +f( D.BatchNum ),
        I.U_XAM_ADU_SIG = I.U_XAM_ADU_SIG + f( D.Located ),
        I.U_XAM_FECHA_SIG = I.U_XAM_FECHA_SIG + f( D.InDate )
FROM    INV1 I
etc.

But get the query written and you're 80% there.
