SELECT
    t1.sa_u8prodpriceid,
    CONCAT(
            'UPDATE rdrecords01 b ',
            'INNER JOIN rdrecord01 h ON b.ID = h.ID ',
            'SET ',
            'b.iOriTaxCost = ', t2.costprice * (100 + IFNULL(t2.taxrate, 0)) / 100,
            ', ',
            'b.iTaxRate = ', IFNULL(t2.taxrate, 0),
            ', ',
            'b.iUnitCost = ', t2.costprice,
            ', ',
            'b.iOriCost = ', t2.costprice,
            ', ',
            'b.fACost = ', t2.costprice,
            ', ',
            'b.iPrice = ', t2.costprice, ' * b.iQuantity',
            ', ',
            'b.iAPrice = ', t2.costprice, ' * b.iQuantity',
            ', ',
            'b.iOriMoney = ', t2.costprice, ' * b.iQuantity',
            ', ',
            'b.iTaxPrice = ', t2.costprice * IFNULL(t2.taxrate, 0) / 100, ' * b.iQuantity',
            ', ',
            'b.iOriTaxPrice = ', t2.costprice * IFNULL(t2.taxrate, 0) / 100, ' * b.iQuantity',
            ', ',
            'b.ioriSum = ', t2.costprice, ' * b.iQuantity + ', t2.costprice * IFNULL(t2.taxrate, 0) / 100, ' * b.iQuantity',
            ', ',
            'b.iSum = ', t2.costprice, ' * b.iQuantity + ', t2.costprice * IFNULL(t2.taxrate, 0) / 100, ' * b.iQuantity',
            ' ',
            'WHERE h.cBusType = ''委外加工'' ',
            'AND h.dDate >= ''', DATE_FORMAT(t1.begindate, '%Y-%m-%d'), ''' ',
            'AND h.dDate <= ''', DATE_FORMAT(t1.enddate, '%Y-%m-%d'), ''' ',
            'AND h.cWhCode = ''', IFNULL(t2.stockno, ''), ''' ',
            'AND b.cinvcode = ''', t2.itemno, ''''
    ) AS sqlstr
FROM
    sa_u8prodprice AS t1
        INNER JOIN
    sa_u8prodprice_datail AS t2
    ON t1.sa_u8prodpriceid = t2.sa_u8prodpriceid
WHERE
    t1.status = '审核'
  AND t1.type = '委外入库';