下面是現有的ms sql server 2008報表查詢。使用多個條件選擇查詢
SELECT
number, batchtype, customer, systemmonth, systemyear, entered, comment, totalpaid
FROM
payhistory LEFT OUTER JOIN agency ON
payhistory.SendingID = agency.agencyid
WHERE
payhistory.batchtype LIKE 'p%' AND
payhistory.entered >= '2011-08-01 00:00:00.00' AND
payhistory.entered < '2011-08-15 00:00:00.00' AND
payhistory.systemmonth = 8 AND
payhistory.systemyear = 2011 AND
payhistory.comment NOT LIKE 'Elit%'
結果會是這樣的:
number batchtype customer systemmonth systemyear entered comment totalpaid
6255756 PC EMC1106 8 2011 12:00:00 AM DP From - NO CASH 33
5575317 PA ERS002 8 2011 12:00:00 AM MO-0051381526 7/31 20
6227031 PA FTS1104 8 2011 12:00:00 AM MO-10422682168 7/30 25
6232589 PC FTS1104 8 2011 12:00:00 AM DP From - NO CASH 103
2548281 PC WAP1001 8 2011 12:00:00 AM NCO DP $1,445.41 89.41
4544785 PCR WAP1001 8 2011 12:00:00 AM NCO DP $1,445.41 39
我所要做的是修改將排除記錄的查詢,其中客戶是像「FTS%」和「EMC%」和batchtype ='PC'。正如你可以在結果集中看到的那樣,客戶的記錄就像FTS%和batchtype ='PA'。我想在結果中保留這些記錄。我希望提供任何想法。
你得到的不良結果是什麼? – CamelSlack
那麼,爲什麼你說「只有當btype ='PC'」,然後把'btype <>'PC''? – Lamak
你的SQL有一個額外的括號,或者它缺少一個... – Matthew