2017-04-06 16 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) 
相关问题