Excel 쿼리에서 작동하는 경우 하나의 필드를 읽고 그 값에 따라 다른 필드를 빼기 (또는하지 않음)로 설정하는 조건문이 필요합니다. 다음과 같이사례, 조건부 요구 사항 선택
내 SQL 코드는 다음과 같습니다
SELECT "_bvSTTransactionsFull".txdate,
SUM("_bvSTTransactionsFull".debit) AS 'TOTALDebit',
SUM("_bvSTTransactionsFull".credit) AS 'TOTALCredit',
SUM("_bvSTTransactionsFull".tax_amount) AS 'TOTALTax_Amount',
SUM("_bvSTTransactionsFull".VALUE) AS 'TOTALValue',
SUM("_bvSTTransactionsFull".actualvalue) AS 'TOTALActualValue',
SUM("_bvSTTransactionsFull".actualsalesvalue) AS 'TOTALActualSalesValue',
SUM("_bvSTTransactionsFull".profit) AS 'TOTALProfit'
FROM sqlschema.dbo."_bvSTTransactionsFull" "_bvSTTransactionsFull"
WHERE ("_bvSTTransactionsFull".txdate >=?
AND "_bvSTTransactionsFull".txdate <=?)
GROUP BY "_bvSTTransactionsFull".txdate,
"_bvSTTransactionsFull".description
HAVING ("_bvSTTransactionsFull".description LIKE 'POS Sale')
OR ("_bvSTTransactionsFull".description LIKE 'POS Return')
ORDER BY "_bvSTTransactionsFull".txdate
내가라는 이름의 필드를 확인하는 선택 쿼리가 필요합니다 "
ActualQuantity
"(테이블 "
_bvSTTransactionsFull
"에서)이 분야는 < 0,
Tax_Amount = -(Tax_Amount)
경우 또는
if ActualQuantity >=0, then Tax_Amount = Tax_Amount
.
쿼리가 "합계"되어 있으므로 합계가 발생하기 전에이 조건부를 처리해야한다고 가정합니다. 쿼리는 대략 100,000 개의 레코드를 일일 합계로 요약합니다.
감사합니다 Nikola,하지만 Excel 2007 쿼리에서 작동하지 않습니다. 표준 오류 –
나는 MS Query에서 case ... end 문을 시도했습니다. 그것은 작동합니다. 이 쿼리를 어떻게 실행합니까? 그리고 그 오류는 무엇입니까? –
Nikola, MS Query에서 SQL 대화 상자를 열고 TAX_Amount의 Sum 문을 다음과 같이 바꿉니다. 합계 ("_bvSTTransactionsFull". 신용) AS 'TOTALCredit', 합계 ("_bvSTTransactionsFull".ActualQuantity> = 0 인 경우) 또 "_bvSTTransactionsFull".tax_amount - "_ bvSTTransactionsFull"TOTALTax_Amount AS .tax_amount 말) ', 오류가 이 –