I have 2 subselects , SQL , which bring 2 different information with the sum of the data. How to do to sum the 2 " sums " and bring in a new column, or a single column?
CASE
WHEN sd3.D3_UM = 'PC' THEN
(SELECT ISNULL(sum(sd3_sub1.D3_QTSEGUM),0) AS D3_QUANT_pc
FROM SD3010 AS sd3_sub1 WITH(NOLOCK)
WHERE sd3_sub1.D3_TM = '010'
AND sd3_sub1.D3_LOCAL IN ('01',
'02',
'98')
AND sd3_sub1.D3_EMISSAO BETWEEN (LEFT(sd3.D3_EMISSAO,6) + '01') AND (LEFT(sd3.D3_EMISSAO,6) + '31')
AND sd3_sub1.D3_FILIAL = sd3.D3_FILIAL
AND sd3_sub1.D3_CC LIKE LEFT(sd3.D3_CC,5) + '%'
AND sd3_sub1.D3_UM = 'PC'
AND sd3_sub1.D_E_L_E_T_ <> '*'
GROUP BY sd3_sub1.D3_UM)
ELSE
(SELECT ISNULL(sum(sd3_sub1.D3_QUANT),0) AS D3_QUANT_not_pc
FROM SD3010 AS sd3_sub1 WITH(NOLOCK)
WHERE sd3_sub1.D3_TM = '010'
AND sd3_sub1.D3_LOCAL IN ('01',
'02',
'98')
AND sd3_sub1.D3_EMISSAO BETWEEN (LEFT(sd3.D3_EMISSAO,6) + '01') AND (LEFT(sd3.D3_EMISSAO,6) + '31')
AND sd3_sub1.D3_FILIAL = sd3.D3_FILIAL
AND sd3_sub1.D3_CC LIKE LEFT(sd3.D3_CC,5) + '%'
AND sd3_sub1.D3_UM <> 'PC'
AND sd3_sub1.D_E_L_E_T_ <> '*'
GROUP BY sd3_sub1.D3_UM)
END producao