2017-04-06 19 views
0

好日子,例如:用這些給定的數據從我的查詢中獲得。SQL 2008:如果一行中的2列具有這些值,則排除行

T0.Date T0.customer T0.total T1.Date, T1.Total 
2.1.2017 BLABLA   2,400.00 3.8.2017 2,400.00 
1.2.2017 BLOBLO   5,000.00 3.1.2017 5,000.00 
1.1.2017 BLEBLE   3,000.00 2.5.2017 3,000.00 
12.5.2016 BLABLA   1,000.00 1.25.2017 1,000.00 

我怎麼可能獲得與T0.Date =一月(1),並在同一行刪除行的想法,T1.Date =月(3)進入查詢。我正在考慮在where子句中使用case,但我不知道如何開始條件。不過,如果T1.Date =月(2),不要緊,如果T0.Date = 1或過去幾年月(2016年1月12日)..

UPDATE: 預期輸出:

T0.Date T0.customer T0.total T1.Date, T1.Total 
2.1.2017 BLABLA   2,400.00 3.8.2017 2,400.00 
1.1.2017 BLEBLE   3,000.00 2.5.2017 3,000.00 
12.5.2016 BLABLA   1,000.00 1.25.2017 1,000.00 
+0

問題尚不清楚。你能否用預期產出清楚解釋清楚? –

+0

就像T1.Date進行中一樣,它不會允許T0.Date是一月。但是,如果T1.Date是2月份,則可以在1月份日期和下面(2016年)下載T0.Date。 – aintno12u

回答

0

這是你想要的嗎?

where T0.Date <> '2017-01-01' or T1.Date <> '2017-03-03' 

或者,如果你只是整個個月

where not ((t0.date >= '2017-01-01' and t0.date < '2017-02-01') and 
      (t1.date >= '2017-03-01' and t1.date < '2017-04-01') 
     ) 
+0

好吧,我在考慮只使用一個月,因爲沒有特定的日期。因爲這個數據是通過日期範圍創建的,所以會有很多日期。所以我的想法是使用MONTH() – aintno12u

0

這應該工作...

where month(dateadd(month,1,T0_date))=month(T1_date) and year(dateadd(month,1,T0_date))=year(T1_date) 
相關問題